2012-12-24 15 views
5

निर्दिष्ट मैं styles.xml में डिफ़ॉल्ट रूप से एक बटन टेक्स्ट का रंग लागू करने के लिएएंड्रॉयड शैली बटन रंग

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

मैं शैली परिवर्तन बटन रंग कैसे कर सकता हूँ, और पूरे आवेदन भर लागू कोशिश कर रहा हूँ? मेरे mainfest में शामिल हैं:

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

यह (जैसे एक TextView के रूप में) सभी पाठ बदलता है, लेकिन एक बटन में पाठ परिवर्तित नहीं होता। अगर मैं ऊपर से रंगीन शैली का उपयोग करता हूं और इसे इस तरह के बटन के लिए 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" />" 

फिर यह पूरी तरह से काम करता है। शैली की वजह से यह सार्वभौमिक रूप से क्यों लागू नहीं होता है? शैलियों.xml के सभी अलग-अलग संस्करण एक ही कोड हैं।

उत्तर

14

मुझे अंततः पता चला कि एक बटन वास्तव में 9-पैच छवि है जो @android पर स्थित है: खींचने योग्य/btn_default पृष्ठभूमि को बदलने के लिए आपको इस छवि को संशोधित करना होगा। बटन टेक्स्ट रंग बदलने के लिए मुझे एक बटन विजेट शैली सेट करनी थी और इसे मेरे ऐप थीम में आयात करना था:

<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> 
संबंधित मुद्दे