我有問題,我真的搜索了很多,浪費了很大的時間,如何在Android的drawable.xml中爲不同風格的solid屬性設置不同的顏色?
我的問題是我有2種風格,每種活動的一種風格,它的孩子當然不同(colorPrimary和colorPrimaryDark),這是2款式:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="adapter_button_color">@color/secondary_orange</item>
</style>
<style name="AppTheme.SurveyStyle" parent="AppTheme">
<item name="colorPrimary">@color/colorPrimary2</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark2</item>
<item name="colorAccent">@color/colorAccent2</item>
<item name="adapter_button_color">@color/button_click</item>
</style>
,和我有raised_selector使用作爲背景按鈕
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/raised_pressed"/><!-- pressed -->
<item android:drawable="@drawable/raised_normal" /> <!-- default -->
繪製名
和raised_normal的例如代碼:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/colorPrimary" />
<stroke
android:width="3dp"
android:color="@color/colorPrimary" />
<padding
android:bottom="1dp"
android:left="1dp"
android:right="1dp"
android:top="1dp" />
<corners
android:bottomLeftRadius="3dp"
android:bottomRightRadius="3dp"
android:topLeftRadius="3dp"
android:topRightRadius="3dp" />
當我設置<solid android:color="@color/colorPrimary" />
一樣,在不同風格的按鈕的顏色是一樣的,所以我搜索和查找,如果我寫 <solid android:color="?attr/colorPrimary" />
反而會獲得風格的主色。
現在好了!所以每個想法都可以使用(?attr/colorPrimary)工作正常,但是如果我設置(?attr/colorPrimary)而不是「@ color/colorPrimary」,應用程序將會崩潰,但是在v-21和更高版本以及最低sdks中。
所以我可以這樣做,並設置顏色取決於風格? 感謝您的時間和感謝閱讀
任何機構可以幫我,一定會很感激 – Mosa