Custom ActionBar appearance in Android 4.3

I customized the appearance of the name of my application in the action bar with the following code

<style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
    <item name="android:textColor">#ff2d2d2d</item>
    <item name="android:textSize">26sp</item>
    <item name="android:fontFamily">sans-serif-condensed</item>
    <item name="android:textAllCaps">true</item>
    <item name="android:textStyle">bold</item>
</style>

In any case, everything works fine on most devices that I tested (3 for clarification), but for 1 - a device running Android 4.3 (Sony Xperia Z), where the style was not applied. I later tested it on an emulator with 4.3 and had the same result.

enter image description here

Is there any way to fix this?

Here is the full style for the application

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

<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="android:Theme.Holo.Light">

        <item name="android:actionBarStyle">@style/myTheme.ActionBar</item>
        <!-- Customize your theme here. -->
        <item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
        <item name="android:buttonStyle">@style/RobotoButtonStyle</item>
        <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_dark</item>

        <item name="android:actionBarItemBackground">@drawable/nav_list_selector</item>

    </style>


    <style name="RobotoTextViewStyle" parent="android:Widget.TextView">
        <item name="android:fontFamily">sans-serif-light</item>
    </style>

    <style name="RobotoButtonStyle" parent="android:Widget.Holo.Button">
        <item name="android:fontFamily">sans-serif-light</item>
    </style>

    <style name="myTheme.ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar">
        <item name="android:titleTextStyle">@style/myTheme.ActionBar.Text</item>
        <item name="android:background">@drawable/action_bar_bg</item>
        <item name="android:searchButtonText">SEARCH</item>
        <item name="android:editTextBackground">@drawable/apptheme_edit_text_holo_dark</item>

    </style>

    <style name="myTheme.ActionBar.Text" parent="@android:style/TextAppearance">
        <item name="android:textColor">#ff2d2d2d</item>
        <item name="android:textSize">26sp</item>
        <item name="android:fontFamily">sans-serif-condensed</item>
        <item name="android:textAllCaps">true</item>
        <item name="android:textStyle">bold</item>
    </style>

</resources>
+4
source share
2 answers

For me it works like a charm. Let me create a custom action bar view

Res / Layout / action_title_view.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="10dp"
        android:ellipsize="end"
        android:maxLines="1"
        android:text=""
        android:textAllCaps="true"
        android:textSize="16sp"
        android:textColor="@color/actionbar_text" />

</RelativeLayout>

Set a custom action bar in your onCreate activity

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // set action bar custom view
    getActionBar().setDisplayShowCustomEnabled(true);
    getActionBar().setDisplayShowTitleEnabled(false);

    LayoutInflater inflator = (LayoutInflater) this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mCustomActionView = inflator.inflate(R.layout.action_title_view, null);

    // assign the view to the actionbar
    getActionBar().setCustomView(mCustomActionView);

    ...
}

setTitle

@Override
public void setTitle(CharSequence title) {
    mTitle = title;
    ((TextView) mCustomActionView.findViewById(R.id.title)).setText(mTitle);
    getActionBar().setTitle("");
}

setTitle, . , .

+4

, , , - , API, -v.

: :

<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Blue</item>

-v11 , :

<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/White</item>

-v14 , :

<style name="TextMedium" parent="@android:style/TextAppearance.Medium">
<item name="android:textColor">@color/Red</item>

( ), api , . , API 13, . api 11 .

: / -v SDK, ( -v16 , -v14).

-v17 (Jelly Bean up), , , api , , Api.

, , , . , Jelly Bean 4.3 , , , Api 17

+1

Source: https://habr.com/ru/post/1526812/


All Articles