Wie legen Sie den Stil für eine Schaltfläche in Android?

Habe ich die unten angegebenen Dateien im res Ordner.

styles_apptheme.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="ButtonAppTheme" parent="android:Widget.Holo.Light.Button">
      <item name="android:background">@drawable/apptheme_btn_default_holo_light</item>
  </style> 
</resources>

themes_apptheme.xml

<?xml version="1.0" encoding="utf-8"?>

<!-- Generated with http://android-holo-colors.com -->
<resources xmlns:android="http://schemas.android.com/apk/res/android">

  <style name="AppTheme" parent="@style/_AppTheme"/>

  <style name="_AppTheme" parent="Theme.AppCompat.Light">

    <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_light</item>

    <item name="android:buttonStyle">@style/ButtonAppTheme</item>

  </style>

</resources>

In meinem Layout.xml Datei, ich habe meine Taste, wie unten

<Button
        android:id="@+id/btnAddTitle"
        android:layout_below="@id/edEnterTitleValue"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/btn_AddTitle"
        android:layout_margin="20dp"
/>

Wenn ich fügen Sie die folgende Zeile zu der Schaltfläche Ansicht oben,

android:background="@style/ButtonAppTheme"

Anwendung abstürzt sagen, dass drawable Ressource sollte festgelegt werden, damit das background-Attribut.

So, ich habe die unten drawable-Datei - abc.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_window_focused="false" android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_normal_holo_light" />
    <item android:state_window_focused="false" android:state_enabled="false"
        android:drawable="@drawable/apptheme_btn_default_disabled_holo_light" />
    <item android:state_pressed="true"
        android:drawable="@drawable/apptheme_btn_default_pressed_holo_light" />
    <item android:state_focused="true" android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_focused_holo_light" />
    <item android:state_enabled="true"
        android:drawable="@drawable/apptheme_btn_default_normal_holo_light" />
    <item android:state_focused="true"
        android:drawable="@drawable/apptheme_btn_default_disabled_focused_holo_light" />
    <item
         android:drawable="@drawable/apptheme_btn_default_disabled_holo_light" />
</selector>

Wenn ich android:background="@drawable/abc" ich sehe nicht ein, das Stil-set in der Schaltfläche.

Also bitte lassen Sie mich wissen, wie ich einstellen kann, den Stil für die Schaltfläche.

Dank.

InformationsquelleAutor der Frage Prem | 2014-09-27

Schreibe einen Kommentar