简体   繁体   中英

How to theme Android Material Theme UI Elements with Appcelerator?

There is this useful information and everything works well: http://docs.appcelerator.com/platform/latest/#!/guide/Android_Themes

The image is also very helpful: 在此处输入图片说明

The problem is that I want to have white or very light gray in the top bar. When I set this as "android:textColorPrimary", however, the text is white in the top bar, but in all alerts for instance as well making it invisible/very difficult to read.

How can I set the text color of the bar to white and theme the alert messages and other text in the default text color (dark gray)?

The themeAndroid.xml in app/platform/android/res/values looks like this

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="materialTheme" parent="@style/Theme.AppCompat.Light">
    <item name="colorPrimary">#2e7d32</item>
    <item name="colorPrimaryDark">#005005</item>
    <item name="colorAccent">#80d8ff</item>
    <item name="colorSwitchThumbNormal">#49a7cc</item>
    <item name="android:colorButtonNormal">#49a7cc</item>
    <item name="android:textColorPrimary">#DADADA</item>
    <item name="android:spinnerItemStyle">@style/SpinnerItem</item>
    <item name="android:spinnerDropDownItemStyle">@style/SpinnerDropDownItem</item>
</style>

If you want to style the color of the actionbar font you need to extend your theme like this:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="Theme.MyThemeActionbar" parent="Theme.AppCompat">
        <item name="colorPrimary">#FF0000</item>
        <item name="colorPrimaryDark">#000000</item>

        <item name="actionBarStyle">@style/CustomTheme.ActionBarStyle</item>
        <item name="actionBarTheme">@style/Theme.ActionBarTheme</item>

        <!-- tab -->
        <item name="actionBarTabTextStyle">@style/TabStyle</item>
        <item name="android:actionBarTabTextStyle">@style/TabStyle</item>
    </style>

    <style name="Theme.ActionBarTheme" parent="style/Widget.AppCompat.Light.ActionBar">
        <!-- actionbar arrow -->
        <item name="colorControlNormal">#ffffff</item>
    </style>

    <style name="CustomTheme.ActionBarStyle" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
        <!-- actionbar -->
        <item name="elevation">0dp</item>
        <item name="android:actionMenuTextColor">#FFFFFF</item>
        <item name="android:titleTextStyle">@style/CustomTheme.ActionBar.TitleTextStyle</item>
        <item name="titleTextStyle">@style/CustomTheme.ActionBar.TitleTextStyle</item>
    </style>

    <style name="CustomTheme.ActionBar.TitleTextStyle" parent="@android:style/TextAppearance.Holo.Widget.ActionBar.Title">
        <!-- actionbar font -->
        <item name="android:textColor">#FFFFFF</item>
    </style>

    <style name="TabStyle" parent="style/Widget.AppCompat.Light.ActionBar.TabText">
        <!-- tab font -->
        <item name="android:textColor">#ffffff</item>
    </style>
</resources>

Then you can set the font color and the primary color to a different value and leave other thinks to the default values

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM