2012-12-24 2 views
5

를 지정 나는안드로이드 스타일의 버튼 색상

<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
<style name="AppTheme"> 
    <item name="android:windowFullscreen">true</item> 
    <item name="android:windowBackground">@color/black</item> 
    <item name="android:textColor">@color/green</item> 
</style> 

가 어떻게 스타일 변경 버튼 색상을 확인하고 전체 응용 프로그램 전체에 적용 할 styles.xml에 기본적으로 버튼 텍스트 색상을 적용하려고? 내 메인 페스트에는 다음이 포함됩니다 :

<application 
    android:icon="@drawable/ic_launcher" 
    android:label="Hack the World" 
    android:theme="@style/AppTheme"> 

이 모든 텍스트 (예 : TextView)가 변경되지만 버튼의 텍스트는 변경되지 않습니다. 내가 위에서 ColorThemes 스타일을 사용하고이 같은 버튼의 XML에 배치 할 경우

<Button 
    android:id="@+id/button3" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerHorizontal="true" 
    android:layout_centerVertical="true" 
    android:onClick="loadSavedgame" 
    android:text="Load Saved Game" 
    android:textColor="@color/green" />" 

를 다음 그것은 완벽하게 작동합니다. 왜 스타일 때문에 보편적으로 적용되지 않습니까? styles.xml의 모든 다른 버전에는 동일한 코드가 있습니다.

답변

14

실제로 단추는 @android : drawable/btn_default에있는 9 패치 이미지로이 이미지를 수정해야하는 배경을 변경한다는 것을 알게되었습니다. 단추 텍스트 색을 변경하려면 버튼 위젯 스타일을 설정하고 내 응용 프로그램 테마로 가져와야했습니다.

<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>