Android style specify button color

前端 未结 1 404
悲哀的现实
悲哀的现实 2021-01-05 10:47

I am trying to apply a button text color by default in styles.xml



        
相关标签:
1条回答
  • 2021-01-05 11:36

    I eventually discovered that a button is, in fact, a 9-patch image that is located at @android:drawable/btn_default in order to change the background you must modify this image. In order to change button text color I had to set a button widget style and import it into my app theme like so:

    <resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" >
       <item name="android:windowFullscreen">true</item>
       <item name="android:windowBackground">@color/black</item>
       <item name="android:textColor">@color/green</item>
       <item name="android:buttonStyle">@style/ButtonText</item>
    </style> 
    
        <style name="ButtonText" parent="@android:style/Widget.Button">
       <item name="android:textColor">@color/green</item>
       <item name="android:background">@android:drawable/btn_default</item><!-- only way to change this is to change the src image -->
       <item name="android:layout_width">80.0px</item>
       <item name="android:layout_height">40.0px</item> 
    </style> 
    </resources>
    
    0 讨论(0)
提交回复
热议问题