Android: Change color of line below ActionBar - android

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.
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.

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>

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

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

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.

Related

RadioButton focus background shape

I want to add focus ripple effect to whole RadioButton, but there is something strange is happening to it when I try to use ripple effect with highlight. In the picture, left is what I get and right is what I want:
background_drawable:
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#color/colorAccent">
<item android:id="#android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#android:color/white"/>
</shape>
</item>
</ripple>
styles.xml
<style name="RadioButtonStyle" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:background">#drawable/radio_button_background</item>
</style>
This happens only If I try to use ripple effect and not if I try to use only shape with selector and state_focused=true as background. For now my workaround is to use warpper View class for RadioButton and set background into it. Is there any way to get background as in the picture but without any additional code? Thanks.
The solution is to set the button attribute to null and set the drawableStart attribute in styles for the radio button:
<style name="RadioButtonStyle" parent="Widget.AppCompat.CompoundButton.RadioButton">
<item name="android:button">#null</item>
<item name="android:drawableStart">#drawable/radio_button_selector</item>
<item name="android:drawablePadding">4dp</item>
<item name="android:background">#drawable/radio_button_background</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingStart">8dp</item>
<item name="android:paddingEnd">8dp</item>
<item name="android:paddingTop">11dp</item>
<item name="android:paddingBottom">11dp</item>
</style>
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="radioButtonStyle">#style/RadioButtonStyle</item>
<item name="android:radioButtonStyle">#style/RadioButtonStyle</item>
</style>
After that focus works as aspected and You can add background to the radio button as You want

Google Now gradient/shadow on status bar & navigation bar

I'm trying to make a similar status bar and navigation bar gradient as Google Now.
Image Reference: Rectangular area indicated as below
After trying the below option on Android Marshmallow,
<item name="android:windowTranslucentNavigation">true</item>
<item name="android:windowTranslucentStatus">true</item>
I get the below behaviour
Image Reference:
Can anyone suggest me how to get gradient on both these ?
Is that a gradient or is that a shadow ?
It is a gradient being used as a scrim. To achieve this effect, the first thing you have to do is remove the semi-transparent underlay for the Status and Navigation bars. Another answer details how you can do this on lower platform devices; but on Android Lollipop and higher, you can do this simply by setting two style attributes to transparent:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>
Then, to add the scrim, you can use a shape drawable:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:type="linear"
android:angle="270"
android:centerY="0.3"
android:startColor="#66000000"
android:centerColor="#33000000"
android:endColor="#00000000"/>
</shape>
Then you can just set this as the background to a View in your layout:
<View
android:layout_width="match_parent"
android:layout_height="72dp"
android:background="#drawable/scrim"/>
You can also set the android:rotation="180" attribute to use the same gradient for the bottom of the screen.
First add a style to make fully transparent action status bar:
<!-- Base application theme. -->
<style name="TransparentTheme" parent="android:Theme.Holo.Light">
<!-- Customize your theme here. -->
<item name="android:windowBackground">#null</item>
<item name="android:actionBarStyle">#style/ActionBarStyle.Transparent</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
<style name="ActionBarStyle.Transparent" parent="android:Widget.ActionBar">
<item name="android:background">#null</item>
<item name="android:displayOptions">showHome|showTitle</item>
<item name="android:titleTextStyle">#style/ActionBarStyle.Transparent.TitleTextStyle</item>
</style>
<style name="ActionBarStyle.Transparent.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#android:color/white</item>
</style>
and to add scrim to it create a drawable file and add this code:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#88000000" />
<gradient
android:angle="90"
android:centerColor="#66000000"
android:centerY="0.3"
android:endColor="#00000000"
android:startColor="#CC000000"
android:type="linear" />
</shape>
and add this as background in your theme;

Customize back button on ActionBar (Android)

in my app i added back button on ActionBar but this is not visible properly because of dark theme of ActionBar. both ActionBar and back Button are black in color so back button is not visible.
i added this code in values.xml file
<style name="Theme.MyFancyTheme" parent="android:Theme.Holo">
<item name="android:homeAsUpIndicator">#drawable/up</item>
</style>
and set.
minSdkVersion="14"
but it's not showing custom back buttom.
In the res/values/styles.xml file put some custom style:
<style name="AppThemeWithBackButton" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/ActionBar</item>
<item name="android:actionMenuTextColor">#color/white</item>
<item name="android:homeAsUpIndicator">#drawable/actionbar_back_button</item>
</style>
<style name="ActionBar" parent="android:Widget.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:displayOptions">useLogo|homeAsUp|showTitle</item>
<item name="android:titleTextStyle">#style/TitleText</item>
</style>
<style name="TitleText" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/white</item>
<item name="android:textAllCaps">false</item>
</style>
and use drawable/actionbar_back_button.xml layout:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:left="16dp"
android:right="16dp"
android:drawable="#drawable/back_icon" />
</layer-list>
and use drawable/actionbar_background.xml layout.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#color/action_bar_color" />
</shape>
Above all code is regarding of customizing actinobar button and background. You can modify it as you want. Hope it will help you. Enjoy!!!

How can I remove divider before actionbar menuItem which only have text on it?

I want to remove short divider before ActionBar's MenuItem which has "withText" option in it.
I've tried many different theme setting with it, but failed.
Is there any solution to remove it?
This is my theme xml.
<style name="my_actionbar" parent="#style/Widget.Sherlock.Light.ActionBar.Solid">
<item name="android:background">#drawable/actionbar_bg</item>
<item name="background">#drawable/actionbar_bg</item>
<item name="android:actionBarDivider">#null</item>
<item name="actionBarDivider">#null</item>
<item name="android:showDividers">none</item>
<item name="android:dividerVertical">#null</item>
<item name="android:dividerPadding">0dp</item>
<item name="android:divider">#null</item>
</style>
The android:actionBarDivider attribute belongs to the theme, not to the action bar style. You can remove the divider like this:
<style name="AppTheme" parent="Theme.Sherlock">
<item name="actionBarDivider">#null</item>
<item name="android:actionBarDivider">#null</item>
</style>
I've solve this problem by set android:listDivider attribute on main theme to some transparent drawble. But I don't know side effects by this setting.
main theme:
<style name="Theme_Main" parent="#style/Theme.Sherlock.Light">
....
<item name="android:listDivider">#drawable/shape_blank</item>
</style>
shape_blank.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line">
<solid android:color="#android:color/transparent"/>
</shape>
I removed divider line from tabbar with use of below magical lines.
mTabHost.getTabWidget().setDividerDrawable(null);
OR
mTabHost.getTabWidget().setDividerDrawable(R.Color.transperant);
Use the below code in your fragment/Activity
getSupportActionBar().setElevation(0);

Change background color of ActionBarSherlock programmatically

I have an ActionBarSherlock on my form. I'm reading style information at runtime. One of the pieces of style is the background color of the ActionBar. How can I change this at runtime? The color can be any RGB value.
Maybe this help : How to set title color in ActionBarSherlock? via style
or getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.ad_action_bar_gradient_bak)); via programmatically
With the theme
// add theme in app
<application android:theme="#style/MainTheme"></application>
// MainTheme
<style name="MainTheme" parent="Theme.Sherlock.Light.DarkActionBar">
</style>
// MainThemeGreen
<style name="MainThemeGreen" parent="Theme.Sherlock.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MainTheme.ActionBarStyle</item>
</style>
// ActionBar
<style name="MainTheme.ActionBarStyle" parent="Widget.Sherlock.Light.ActionBar">
<item name="android:background">#drawable/bg_green_actionbar</item>
<item name="android:titleTextStyle">#style/MainTheme.ActionBar.TitleTextStyle</item>
</style>
// Text style
<style name="MainTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#color/White</item>
</style>
// bg_green_actionbar.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="#ff74af3b" />
</shape>
</item>
</layer-list>
After this you can change Theme on fly: setTheme(R.styles.MainThemeGreen);
One way:
mSupportActionBar = getSupportActionBar();
mSupportActionBar.setBackgroundDrawable(new ColorDrawable(0xff123456));
where 0xff123456 is your required ARGB integer.
I just used below Code
getSupportActionBar().setBackgroundDrawable(new
ColorDrawable(Color.parseColor("#00853c")));
it changed the bg color. Hope, it helps.

Categories

Resources