Android Styles For API 10 and API 11

微笑、不失礼 提交于 2020-01-05 08:06:23

问题


I am trying to do something that I feel to be very simple in concept. I would like my app to be supported all the way back to API 10 (Gingerbread). To make this look good, I need to make a slight change to the color of the text on my buttons when the device is running API 10. Thus, I want to create two styles: one of which will be used when the device is using API 10 (I want the text color of the buttons to be black in this case), and another when the device is using API 11 or above (the text color will be the default ICS grayish in this case). To do this, I am using a values and a values-v11 folder. Inside the values folder is a themes.xml file with the following code:

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
    <style name="buttonColorStyle">
        <item name="android:textAppearanceButton">@style/buttonTextColor</item>
    </style>

    <style name="buttonTextColor">
       <item name="android:textColor">#FFFFFF</item>
    </style>
</resources> 

However, when I load up my app with target SDK set to 10, the text color of the buttons is unchanged from the default grayish. Also, here is the code for one of my buttons which should use this style:

<Button
        style="@style/buttonColorStyle"
        android:id="@+id/thirdSectionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:onClick="sectionButtonClicked"
        android:text="Section 3"
        android:textSize="11.5sp" />

Anyone have any ideas?


回答1:


why not setting the same nice style for all versions?

you can use this library (also suggested at the android developers blog here) for making all of the devices use the holo theme.

alternatively , just leave the current style , so that the user will feel more "at home" with his current style of the OS (since it can change between companies) .




回答2:


You have to do something like this:

 <style name="MyStlye">
        <item name="android:textAppearanceButton">@style/BtnText</item>
 </style>

 <style name="BtnText" parent="android:TextAppearance.Small.Inverse">
        <item name="android:textColor">@android:color/black</item> // or whatever color
 </style>


来源:https://stackoverflow.com/questions/14167063/android-styles-for-api-10-and-api-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!