How to combine style into a theme? - java

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.

Related

I want to change title bar text color in material Components theme. Any help will be greatly appreciated

I tried set title color but it is deprecated. I tried to change color by using
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyTheme.ActionBarStyle</item>
</style>
<style name="MyTheme.ActionBarStyle" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.ActionBar.TitleTextStyle" parent="#android:style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/red</item>
</style>
as mentioned here: ActionBar text color but the whole Titlebar color changes to white while doing it.
All I want to do is set my Black Title bar text color to white.
I also tried this solution here: Change color title bar but I am using the MaterialComponents theme and using AppCompactThemes makes my app crash.
Assuming that you are not using a Toolbar the textcolor used in the ActionBar is based on the attribute android:textColorPrimary.
You can override it adding in your app theme the actionBarTheme attribute:
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="actionBarTheme">#style/ThemeOverlay.Actionbar</item>
</style>
with:
<style name="ThemeOverlay.Actionbar" parent="ThemeOverlay.MaterialComponents.ActionBar.Surface" >
<item name="android:textColorPrimary">#color/....</item>
</style>
As alternative you can
just add this to you base theme
<item name="titleTextColor">#android:color/holo_red_dark</item> //whatever color
Eg:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="titleTextColor">#android:color/holo_green_dark</item>
</style>

Change action bar Title font & color

I wanna change my action bar title font & color. so now im doing like this code. also i'm using typekit library too. i dont know why not change now
plz have some advice for me
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorCyanAzure</item>
<item name="colorPrimaryDark">#color/colorWhite</item>
<item name="colorAccent">#color/colorMelon</item>
<item name="android:actionBarStyle">#style/AppTheme.MyActionBar</item>
</style>
<style name="AppTheme.MyActionBar" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/MyTheme.MyActionBar.TitleTextStyle</item>
</style>
<style name="MyTheme.MyActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textStyle">normal</item>
</style>
Change you Theme.AppCompat.Light to Theme.AppCompat.Light.DarkActionBar and tried code as below
<style name="AppBaseTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<style name="AppTheme.MyActionBar"parent="#style/Widget.AppCompat.ActionBar.Solid">
<item name="titleTextStyle">#style/MyTitleTextStyle</item>
</style>
<style name="MyTheme.MyActionBar.TitleTextStyle" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/colorWhite</item>
<item name="android:textStyle">normal</item>
</style>
You could use a toolbar. When you have a reference to the toolbar and you want to style the title, you could do something like this
TextView textView = (TextView)toolbar.getChildAt(0);
//set the font and font color.
If you have more children in the toolbar, you may want to loop through and find the child you want to 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>

Categories

Resources