2016-04-26 10 views
1

Ich versuche, Hintergrund mit Vollbild zu erstellen, aber nur ein graues Quadrat haben.Problem mit Hintergrundbild

enter image description here

Die correc TImage: enter image description here

ich hinzufügen Bild in Projekt die neue/Image-Asset von Android Studio verwenden.

Aktivität Layout

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:paddingBottom="@dimen/activity_vertical_margin" 
     android:paddingLeft="@dimen/activity_horizontal_margin" 
     android:paddingRight="@dimen/activity_horizontal_margin" 
     android:paddingTop="@dimen/activity_vertical_margin" 
     android:background="@drawable/mainbackground" 
     tools:context="com.imagenia.rollaction.rollaction.MainActivity"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Al menu" 
      android:id="@+id/boton" 
      android:layout_centerVertical="true" 
      android:layout_centerHorizontal="true" /> 
    </RelativeLayout> 

Manifest // Ich wechsle das Thema

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@android:style/Theme.Light.NoTitleBar.Fullscreen"> 
    <activity 
     android:name=".MainActivity" 
     android:screenOrientation="landscape"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <activity 
     android:name=".ActividadPrincipal" 
     android:screenOrientation="landscape"> 


    </activity> 
</application> 

ED IT

Ich versuche, direkt PNG-Datei, in Android-Bild-Taste hinzufügen. aber haben ein sema-problem, die bild-taste sind grau-quadrat.

+0

Verwenden Sie PNG-Bild? –

+0

Ja, Android Studio meine JPEG in PNG-Datei ändern. –

Antwort

1

Versuchen Sie, das Bild direkt in den Ordner res/drawable einzufügen. Kopieren Sie den Ursprung und fügen Sie ihn direkt in den Zeichnungsordner ein. Es sollte funktionieren. Der Code scheint korrekt zu sein. Es sollte das Hintergrundbild laden.

+1

Danke, Problem ist im Import mit neuem Bild-Asset –

0

Um eine Schaltfläche mit dem benutzerdefinierten Hintergrund erstellen Sie Android TextView statt der Button und verwenden android:background Attribut für Schaltfläche Bild und android:text für Button-Text verwenden können.