Removing default actionbar tab padding - java

My problem is that I can't seem to override androids default tab padding and it's making my tabs horizontally scrollable (which I don't want). I've searched around stack overflow and other sites online but i can't find a solution for my problem. I am using appcompat-v7 and I'm targeting api 21 with my minimum sdk set to api 14.
Here is my themes.xml
<style name="TSTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabStyle">#style/ActionBarTabStyle</item>
<item name="colorPrimary">#color/primary_blue_500</item>
<item name="colorPrimaryDark">#color/dark_blue</item>
<item name="colorAccent">#color/primary_blue_500</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/primary_blue_500</item>
</style>
<style name="ActionBarTabStyle"
parent="#style/Widget.AppCompat.Light.ActionBar.TabView.Inverse">
<item name="android:paddingLeft">0dp</item>
<item name="android:paddingRight">0dp</item>
<item name="android:paddingBottom">0dp</item>
<item name="android:paddingTop">0dp</item>
</style>
I have tried adding android: prefix but it still doesn't do anything. I have also defined my custom theme in my manifest
Any and all help is much appreciated

For this you will have to create your own style and then you can set that style to actionbar manually. This is the only way to make it done.
<item name="toolbarStyle">#style/Widget.Toolbar</item>
<style name="Widget.Toolbar" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">0dp</item>
</style>

Related

How to combine style into a theme?

I have created a style:
<style name="Button_Display">
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:gravity">center_vertical|center_horizontal</item>
</style>
I want that all the Button's in my application will look like declared above.
My question is how can i combine the Button_Display style inside a theme so all the Buttons in my app will have this look and feel?
https://developer.android.com/guide/topics/ui/look-and-feel/themes
In styles.xml create your own button style. Choose whatever parent style matches your need the best. Then overwrite all the necessary parameters.
<style name="myButtonStyle" parent="#style/Widget.AppCompat.Button">
<item name="android:minHeight">48dip</item>
<item name="android:minWidth">88dip</item>
...
</style>
Then set this as default button style in your theme.
<style name="AppTheme" parent="Theme.AppCompat....">
<item name="buttonStyle">#style/myButtonStyle</item>
...
</style>
Now all Buttons will have the parameters you specified in your style.

How to Change swipe Tab Title color in java Android

By Default, the View Pager(Swipe Tabs) Tab title color is White but i want to change into orange. Can any one help me please or share if you have any tutorial.
Thanks...
Use this style in your styles.xml and assign the style to your tab layout.
<style name="MyMaterialTheme.TabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabIndicatorHeight">3dp</item>
<item name="tabTextAppearance">#style/MyMaterialTheme.TabLayout.TextAppearance</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="android:background">#color/colorPrimary</item>
</style>
<style name="MyMaterialTheme.TabLayout.TextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#color/tab_text_inactive</item>
<item name="textAllCaps">true</item>
</style>
Check implementation from here.

Custom Background Color for ActionBar settings area

I would like to change the color of my settings Tab located on the ActionBar, I have done very extensive research here and in other sources.
My Android version is 4.4.2.
My manifest is declared this way:
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="19" />
Basically I am doing what other sources showed me to:
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:panelFullBackground">#drawable/menu_background</item>
</style>
I also have replaced the android:panelFullBackground property for android:panelBackground, android:panelColorBackground and android:panelColorForeground switching from drawable resources to color values for each without results.
Finally I have also tried using ListPopupWindow parent variant:
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<item name="android:popupMenuStyle">#style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="#android:style/Widget.Holo.ListPopupWindow">
<item name="android:panelFullBackground">#drawable/menu_background</item>
</style>
Here I have also switched the android:panelFullBackground property for android:panelColorBackground and android:popupBackground properties mixing them up with #android:color and #drawable resources too but is not working either.
Can you please tell me an effective way to configure this through the styles.xml file?
Thank you very much
Maybe you need to use Android Asset studio's ActionBarStyleGenerator to easily handle colors and not going through all the stuff. If you need more customizing on each Tab then you need to get a reference to actionbar using getActionBar()(or getSupportActionBar() in case of support actionbar) and create custom views Programmatically and add them to your actionbar using addTab(...)
I managed to find the right setting for my styles to accomplish the action bar settings custom color. This post helped as well: How to change the background color of Action Bar's Option Menu in Android 4.2?
The styles go this way:
File styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:style/Theme.Holo.Light">
</style>
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
<item name="android:popupMenuStyle">#style/PopupMenu</item>
<item name="android:itemTextAppearance">#style/TextAppearance</item>
</style>
<style name="MyActionBarTheme" parent="#android:Widget.Holo.Light.ActionBar">
<item name="android:background">#3892D3</item>
<item name="android:titleTextStyle">#style/MyActionBarTheme.Text</item>
</style>
<!--
This style reference did it, you can put a drawable resource or color resource reference there as well. For example: #drawable/menu_dropdown_image or #android:color/white
-->
<style name="PopupMenu" parent="#android:Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#3892D3</item>
</style>
<!---->
<style name="MyActionBarTheme.Text" parent="#android:TextAppearance">
<item name="android:textColor">#android:color/white</item>
<item name="android:textSize">20sp</item>
</style>
<style name="TextAppearance">
<item name="android:textColor">#android:color/white</item>
</style>
</resources>
Thank you!

Change the action bar settings icon color

How can one change the color of the overflow icon in the action bar?
(The most right icon)
You can use something like this
<style name="MyTheme" parent="android:style/Theme.Holo.Light">
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverflow</item>
</style>
<style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:src">#drawable/my_action_bTutton_overflow</item>
</style>
in your AndroidManifest.xml
<application
android:theme="#style/MyTheme" >
If you want to change actionBar color
#style/MyActionBar
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/app_theme_color</item>
<!-- Support library compatibility -->
<item name="background">#color/app_theme_color</item>
<item name="android:alwaysDrawnWithCache">true</item>
<item name="android:displayOptions">showTitle|showHome|homeAsUp</item>
<item name="android:icon">#android:color/transparent</item>
</style>
Then in your AndroidManifest.xml you need to refer this one inside your application tag.
android:theme="#style/CustomActionBarTheme"
If you just want to change the color you can simply tint it:
<style name="DotsDarkTheme" parent="#style/Widget.AppCompat.ActionButton.Overflow" >
<item name="android:tint">#color/yourColor</item>
</style>
and then use it in your style:
<item name="actionOverflowButtonStyle">#style/DotsDarkTheme</item>
if you are using action bar use :
toolbar.getOverflowIcon().setColorFilter(Color.WHITE , PorterDuff.Mode.SRC_ATOP);
It's also worth adding that if you simply want to change the overflow button to a light or dark colour to go with your action bar colour this can be done without specifying a custom icon.
For a dark button colour set your theme as:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
</style>
For a light button colour add DarkActionBar:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
</style>
If, like me, you want a light button colour but you want the overflow menu to be light you can do the following:
<style name="MyTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyTheme.ActionBar</item>
<item name="android:actionBarWidgetTheme">#style/MyTheme.ActionBarWidget</item>
</style>
<!-- This helps the PopupMenu stick with Light theme while the ActionBar is in Dark theme -->
<style name="MyTheme.ActionBarWidget"
parent="android:Theme.Holo.Light">
<item name="android:popupMenuStyle">#android:style/Widget.Holo.Light.PopupMenu</item>
<item name="android:dropDownListViewStyle">#android:style/Widget.Holo.Light.ListView.DropDown</item>
</style>
You can use your custom style inside for menu item, like this
<item name="android:itemTextAppearance">#style/myCustomMenuTextApearance</item>
Define the style like this:
<style name="myCustomMenuTextApearance" parent="#android:style/TextAppearance.Widget.IconMenu.Item">
<item name="android:textColor">#android:color/primary_text_dark</item>
</style>
Also see Change the background color of the options menu and
Android: customize application's menu (e.g background color)
Create below style in styles.xml with parent as ActionButton Overflow widget
and then use that theme in the style that you are using for that activity where toolbar is shown.
Step-1) Creating style for the actionButtonOverflow
<style name="DotsDarkTheme" parent="#style/Widget.AppCompat.ActionButton.Overflow" >
<item name="android:tint">your color</item>
</style>
Step-2) Using this style in the activity that is using actionBar
<style name="CustomMainActivityTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="actionOverflowButtonStyle">#style/DotsDarkTheme</item>
</style>

Change ActionBar text color

I want to change my ActionBar color to blue (#0c01e3). My code is working because the actionbar background property is doing its job. But the text won't change. Any ideas? I'm using ABS.
<style name="MyActionBar1" parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="android:backgroundSplit">#06e301</item>
<item name="android:backgroundStacked">#06e301</item>
<item name="android:background">#06e301</item>
<item name="background">#06e301</item>
<item name="backgroundSplit">#B9001F</item>
<item name="android:textColor">#0c01e3</item>
>
Update
:
Set this in your Java Page .It works for me
ActionBar ab = getActionBar();
ab.setTitle(Html.fromHtml("<font color='#ffffff'>App Name</font>"));
On the theme, there is an attribute, actionItemTextColor, which controls this color.
Remember to specify it with and without the android: prefix when using ActionBarSherlock.
add this and then try
    <item name="android:textColor">#ffffff</item>
To improve on the answer of #IntelliJ Amiya:
getActionBar().setTitle(
Html.fromHtml("<font color='" + getResources().getColor(R.color.my_color) + "'>"
+ getString(R.string.title_home) + "</font>"));
If you want to change that using xml ...
This is what worked for me ...
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/titleBarBgColor</item>
<item name="android:titleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<item name="android:subtitleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<!-- Support library compatibility -->
<item name="background">#color/titleBarBgColor</item>
<item name="titleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
<item name="subtitleTextStyle">#style/EldTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="EldTheme.ActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/titleBarTextColor</item>
</style>

Categories

Resources