2012-12-24 39 views
5

Tôi cố gắng để áp dụng một màu nút văn bản theo mặc định trong styles.xmlphong cách Android chỉ định nút màu

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

Làm thế nào để làm cho các nút thay đổi màu sắc theo phong cách, và áp dụng trong suốt toàn bộ ứng dụng? My mainfest bao gồm:

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

Điều này thay đổi tất cả văn bản (như TextView), nhưng không thay đổi văn bản trong một nút. Nếu tôi sử dụng kiểu ColorThemes từ trên cao và đặt nó vào xml cho nút như sau:

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

Sau đó, nó hoạt động hoàn hảo. Tại sao điều này không áp dụng phổ biến vì phong cách? Tất cả các phiên bản khác nhau của styles.xml có cùng mã.

Trả lời

14

Cuối cùng tôi đã phát hiện ra rằng một nút, trên thực tế, một hình ảnh 9-bit được đặt tại @android: drawable/btn_default để thay đổi nền, bạn phải sửa đổi hình ảnh này. Để thay đổi màu chữ của nút, tôi phải đặt kiểu tiện ích nút và nhập nó vào chủ đề ứng dụng của mình như vậy:

<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> 
Các vấn đề liên quan