Android: Change color of line below ActionBar

2019-01-18 07:07发布

I want to change the color of the orange line below the ActionBar.

http://s14.directupload.net/images/130911/3suejbj2.png

I've tried a few things but nothing has helped so far.

The current theme on my Galaxy S2 is an orange theme. So changing the theme, also changes the line. But I don´t know how to get access to that line, in order to change the color.

4条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-18 07:41

I used this ^_^ and it is 100% working:

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Drawable res = getResources().getDrawable(R.drawable.ab_transparent_example);
    getActionBar().setBackgroundDrawable(res);

and JUST USE THIS .9.png

查看更多
在下西门庆
3楼-- · 2019-01-18 07:45

In my case, in my application, I used the Holo theme.

<style name="AppTheme" parent="android:Theme.Holo">
       ...
 </style>

Background toolbar is set through the property.

<style name="AppTheme" parent="android:Theme.Holo">
    <item name="android:actionBarStyle">@style/ActionBarStyle</item>
</style>

<style name="ActionBarStyle" parent="@android:style/Widget.Holo.ActionBar">
    <item name="android:background">@drawable/action_bar_background</item>
</style>

Standard Holo action bar background is nine-patch drawable like this:
nine patch drawable

So, if you want to change the color of the bottom line, you need to create a new nine-patch drawable. Create Resizable Bitmaps (9-Patch files)

Put the file in the folder drawable (example drawable-xxhdpi) and specify the path to the file in the theme.

查看更多
Ridiculous、
4楼-- · 2019-01-18 07:46

There is A simpler way than this (Creating Bunch of Styles). Refering to this . Just set

getActionBar().setBackgroundDrawable(null);

This will Remove the line from Your Action Bar

查看更多
爷的心禁止访问
5楼-- · 2019-01-18 07:51

You can use This code for achieving your purpose.

background.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list
    xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#ff0000" />
        </shape>
    </item>
    <item android:bottom="5dp">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff" />
        </shape>
    </item>
</layer-list>

styles.xml

<resources>
    <style name="AppTheme" parent="android:Theme.Holo">
        <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
        <item name="android:background">#ffffff</item>
        <item name="android:colorBackground">#ffffff</item>
    </style>
    <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
        <item name="android:background">@drawable/background</item>
    </style>
</resources>

These codes are suitable when you have not any options menu like image shows in question, if you have options menu you must customize your option menu items background.

If you have Option menu below code is suitable:

<resources>
    <style name="AppTheme" parent="android:Theme.Holo.Light">
        <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
        <item name="android:popupMenuStyle">@style/AppTheme.PopUpMenu</item>
    </style>
    <style name="AppTheme.ActionBar" parent="android:Widget.ActionBar">
        <item name="android:background">@drawable/background</item>
    </style>
    <style name="AppTheme.PopUpMenu" parent="android:Widget.Holo.Light.ListPopupWindow">
        <item name="android:popupBackground">@drawable/background</item>
    </style>
</resources>
查看更多
登录 后发表回答