Android: Change color of line below ActionBar

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

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

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

回答1:

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> 


回答2:

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



回答3:

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



回答4:

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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!