Customizing themes for Android API 9 and 10

Asked

Viewed 149 times

1

I have an App that runs from API 9 to Android 23, however the text colors are different from the set colors, the correct would be Blue Toolbar with white text. The problem only occurs in API 9 and 10.

Imagem do App em um dispositivo da API 10

And the style is as follows:

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="ThemeAccent" parent="AppTheme">
    <item name="colorAccent">@color/colorPrimary</item>
</style>

Any solution to this problem?

Thanks in advance!

1 answer

1


I advise using a Toobar, because it is much more practical and easy. In your layouts put:

  <android.support.v7.widget.Toolbar
        android:id="@+id/toobar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/colorPrimary"
        app:theme="@style/toobarStyle"
        android:elevation="3dp"
        />

In your style put:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>     
</style>
<style name="toobarStyle" parent="Theme.AppCompat">
    <item name="popupTheme">@style/Theme.AppCompat.Light</item>
    <item name="colorControlNormal">@color/colorAccent</item>
</style>

In the color file use:

<resources>
  <color name="colorPrimary">sua cor</color>
  <color name="colorPrimaryDark">sua cor</color>
  <color name="colorAccent">#fff</color>
</resources>

In the onCreate of your activitys put:

    Toolbar toobar = (Toolbar)findViewById(R.id.toolbar);
    setSupportActionBar(toobar);
  • I will make some changes to the style, and I’m already using Toolbar. Thanks for the effort! : D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.