Parent style for TextView style with AppCompat usage - android

What parent style should I use if I want to set global textViewStyle and maintain backward compatibility with AppCompat? I can't find something like Widget.AppCompat.TextView :
<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textViewStyle">#style/GlobalTextViewStyle</item>
</style>
<style name="GlobalTextViewStyle" parent="?????">
<item name="android:textAppearance">#style/TextAppearance.AppCompat.Medium</item>
</style>

You just need to extend TextAppearance.AppCompat style overriding necessary values:
<style name="Base_AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:textAppearance">#style/MyTextAppearance</item>
</style>
<style name="MyTextAppearance" parent="TextAppearance.AppCompat">
<item name="android:textColor">?android:textColorPrimary</item>
<item name="android:textColorHint">?android:textColorHint</item>
<item name="android:textColorHighlight">?android:textColorHighlight</item>
<item name="android:textColorLink">?android:textColorLink</item>
<item name="android:textSize">#dimen/abc_text_size_body_1_material</item>
<item name="textColor">?textColorPrimary</item>
<item name="textColorHighlight">?textColorHighlight</item>
<item name="textColorHint">?textColorHint</item>
<item name="textColorLink">?textColorLink</item>
<item name="textSize">16sp</item>
<item name="textStyle">normal</item>
</style>

If you want to set this style for all your TextView's in your app, you can do something like this:
<resources>
<style name="YourTheme" parent="android:YourParentThTheme">
<item name="android:textViewStyle">#style/GlobalTextViewStyle </item>
</style>
<style name="GlobalTextViewStyle" parent="android:Widget.TextView">
<item name="android:textColor">#FF000</item>
<item name="android:textStyle">bold</item>
</style>
</resources>

<style name="normal_text_white" parent="#android:style/TextAppearance.Medium">
<item name="android:textColor">#color/white_color</item>
<item name="android:textSize">#dimen/small_text_size</item>
<item name="android:textColorHint">#color/hint_color</item>
</style>

We can try this as well for AppCompat widget.
<style name="TitleStyle" parent="TextAppearance.AppCompat">
<item name="android:gravity">center_horizontal</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:textSize">26sp</item>
</style>

Related

Changing textstyle of popupmenu in themes.xml doesn't work

I would like to change the textsize of popupmenu,so I try it in styles.xml and themes.xml,but the textsize seems to be override by android:textViewStyle.If I delete android:textViewStyle in my themes.xml,the textsize of popupmenu works.Is there something wrong in my code?
styles.xml
<style name="mytextviewstyle" parent="Widget.MaterialComponents.TextView">
<item name="android:gravity">center_vertical</item>
<item name="android:textAppearance">#dimen/body_text_appearance</item>
<item name="minHeight">#dimen/body_text_minHeight</item>
<item name="android:textSize">32sp</item>
</style>
<style name="mypopmenustyle" parent="Widget.MaterialComponents.PopupMenu.Overflow">
<item name="android:textSize">#16sp</item>
<item name="android:textColor">#color/white</item>
<item name="android:popupBackground">?attr/colorPrimary</item>
</style>
themes.xml
<item name="android:textViewStyle">#style/mytextviewstyle</item>
<item name="actionOverflowMenuStyle">#style/mypopmenustyle</item>
By the way,android:buttonStyle and buttonStyle don't work too.Still get the default button.
styles.xml
<style name="mybottonstyle" parent="Widget.MaterialComponents.Button">
<item name="android:gravity">center_vertical</item>
<item name="android:textAppearance">#dimen/body_text_appearance</item>
<item name="android:textSize">#dimen/body_textSize</item>
</style>
themes.xml
<item name="android:buttonStyle">#style/mybottonstyle</item>
<item name="buttonStyle">#style/mybottonstyle</item>

Android make a button borderless by combine two styles doesn't work

I want to make a back button with the styles like:
<style name="back_button" parent="Widget.AppCompat.Button.Borderless">
<item name="android:fontFamily">#font/frutiger_light</item>
<item name="android:textColor">#color/lightSaber</item>
<item name="android:textSize">16sp</item>
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
But right now I already have one exited style:
<style name="FrutigerLight16LightSaber">
<item name="android:fontFamily">#font/frutiger_light</item>
<item name="android:textColor">#color/lightSaber</item>
<item name="android:textSize">16sp</item>
</style>
So I want to add a new style with Widget.AppCompat.Button.Borderless and FrutigerLight16LightSaber.
I tried two solutions by combing . and parent, but doesn't work.
ONE:
<style name="FrutigerLight16LightSaber.Borderless" parent="Widget.AppCompat.Button.Borderless">
</style>
then
<style name="back_button" parent="FrutigerLight16LightSaber.Borderless">
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
in this way, I lost FrutigerLight16LightSaber style.
TWO
<style name="FrutigerLight16LightSaberBorderless" parent="FrutigerLight16LightSaber">
<item name="android:borderlessButtonStyle">#style/Widget.AppCompat.Button.Borderless</item>
</style>
then
<style name="back_button" parent="FrutigerLight16LightSaberBorderless">
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>
this way I lost Widget.AppCompat.Button.Borderless.
Thanks for any help!
Try using
<style name="FrutigerLight16LightSaber.Borderless" parent="Widget.AppCompat.Button.Borderless">
<item name="android:fontFamily">#font/frutiger_light</item>
<item name="android:textColor">#color/lightSaber</item>
<item name="android:textSize">16sp</item>
</style>
And then use like below:
<style name="back_button" parent="FrutigerLight16LightSaber.Borderless">
<item name="android:textAllCaps">false</item>
<item name="android:text">#string/back</item>
<item name="android:background">#android:color/transparent</item>
</style>

Change text color and size of actionbar

I try to change text color and size of my actionbar through the style resources:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="Theme.Example3" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarItemBackground">#drawable/selectable_background_example3</item>
<item name="android:popupMenuStyle">#style/PopupMenu.Example3</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example3</item>
<item name="android:actionBarTabStyle">#style/ActionBarTabStyle.Example3</item>
<item name="android:actionDropDownStyle">#style/DropDownNav.Example3</item>
<item name="android:actionBarStyle">#style/ActionBar.Solid.Example3</item>
<item name="android:actionModeBackground">#drawable/cab_background_top_example3</item>
<item name="android:actionModeSplitBackground">#drawable/cab_background_bottom_example3</item>
<item name="android:actionModeCloseButtonStyle">#style/ActionButton.CloseMode.Example3</item>
</style>
<style name="ActionBar.Solid.Example3" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_example3</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_example3</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_example3</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example3</item>
</style>
<style name="Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle" parent="#android:style/TextAppearance.Medium">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#color/white</item>
</style>
<style name="ActionBar.Transparent.Example3" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/ab_transparent_example3</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example3</item>
</style>
<style name="PopupMenu.Example3" parent="#android:style/Widget.Holo.Light.ListPopupWindow">
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example3</item>
</style>
<style name="DropDownListView.Example3" parent="#android:style/Widget.Holo.Light.ListView.DropDown">
<item name="android:listSelector">#drawable/selectable_background_example3</item>
</style>
<style name="ActionBarTabStyle.Example3" parent="#android:style/Widget.Holo.Light.ActionBar.TabView">
<item name="android:background">#drawable/tab_indicator_ab_example3</item>
</style>
<style name="DropDownNav.Example3" parent="#android:style/Widget.Holo.Light.Spinner">
<item name="android:background">#drawable/spinner_background_ab_example3</item>
<item name="android:popupBackground">#drawable/menu_dropdown_panel_example3</item>
<item name="android:dropDownSelector">#drawable/selectable_background_example3</item>
</style>
<style name="ProgressBar.Example3" parent="#android:style/Widget.Holo.Light.ProgressBar.Horizontal">
<item name="android:progressDrawable">#drawable/progress_horizontal_example3</item>
</style>
<style name="ActionButton.CloseMode.Example3" parent="#android:style/Widget.Holo.Light.ActionButton.CloseMode">
<item name="android:background">#drawable/btn_cab_done_example3</item>
</style>
<!-- this style is only referenced in a Light.DarkActionBar based theme -->
<style name="Theme.Example3.Widget" parent="#android:style/Theme.Holo">
<item name="android:popupMenuStyle">#style/PopupMenu.Example3</item>
<item name="android:dropDownListViewStyle">#style/DropDownListView.Example3</item>
</style>
</resources>
The above style.xml contains following code part, which should change text color and size, but it happens nothing on my actionbar:
<style name="Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle" parent="#android:style/TextAppearance.Medium">
<item name="android:textSize">20sp</item>
<item name="android:textColor">#color/white</item>
</style>
What is wrong?
Thanks!!
<item name="android:titleTextStyle">#style/Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle</item>
is missing in <style name="ActionBar.Solid.Example3">
The problem is that you need to link the third block of style from inside the second block of style:
<style name="ActionBar.Solid.Example3" parent="#android:style/Widget.Holo.Light.ActionBar.Solid">
<item name="android:background">#drawable/ab_solid_example3</item>
<item name="android:backgroundStacked">#drawable/ab_stacked_solid_example3</item>
<item name="android:backgroundSplit">#drawable/ab_bottom_solid_example3</item>
<item name="android:progressBarStyle">#style/ProgressBar.Example3</item>
<item name="android:titleTextStyle">#style/Theme.Example3.ActionBar.Solid.Example3.TitleTextStyle</item>
</style>

Styling ActionBar Sherlock

I'm trying to customize my sherlock action bar, but nothing that I code in my style.xml is recognized.
In my manifest file:
android:theme="#style/Theme.Sherlock"
My style.xml:
<resources>
<style name="Theme.MyAppTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/Theme.MyAppTheme.ActionBar</item>
</style>
<style name="Theme.MyAppTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#222222</item>
<item name="android:height">64dip</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">32sp</item>
</style>
I'm calling my actionbar this way:
public class MainActivity extends SherlockActivity {
com.actionbarsherlock.app.ActionBar actionbar;
...
actionbar = getSupportActionBar();
... }
There is no problem in showing the actionbar, but the same does not show any customization coded in style.xml, can someone help me? Thankful.
It's because you are applying the same original style in the manifest file android:theme="#style/Theme.Sherlock" which doesn't make any difference. You have prepared the custom style with name Theme.MyAppTheme, having parent as Theme.Sherlock. So, you need to declare your customized style(Theme.MyAppTheme) in your manifest file like android:theme="#style/Theme.MyAppTheme". Even you have to include without android prefix attributes too like below as the other answerer also said. Hope this helps. Even you can refer this too.
<style name="Theme.MyAppTheme" parent="Theme.Sherlock.Light">
<item name="android:actionBarStyle">#style/Theme.MyAppTheme.ActionBar</item>
<item name="actionBarStyle">#style/Theme.MyAppTheme.ActionBar</item>
</style>
<style name="Theme.MyAppTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#222222</item>
<item name = "background">#222222</item>
<item name="android:height">64dip</item>
<item name="height">64dip</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
<item name="textColor">#fff</item>
<item name="android:textStyle">bold</item>
<item name="textStyle">bold</item>
<item name="android:textSize">32sp</item>
<item name="textSize">32sp</item>
</style>
Use this and you don't need to create your own style
Action Bar Style Generator
This:
<item name="android:actionBarStyle">#style/Theme.MyAppTheme.ActionBar</item>
is for the default ActionBar, notice the 'android:'.
You have to style it like this:
<resources>
<style name="Theme.MyAppTheme" parent="Theme.Sherlock">
<item name="android:actionBarStyle">#style/Theme.MyAppTheme.ActionBar</item>
<item name="actionBarStyle">#style/Theme.MyAppTheme.ActionBar</item>
</style>
<style name="Theme.MyAppTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#222222</item>
<item name="android:height">64dip</item>
<item name="background">#222222</item>
<item name="height">64dip</item>
<item name="android:titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
<item name="titleTextStyle">#style/Theme.MyAppTheme.ActionBar.TitleTextStyle</item>
</style>
<style name="Theme.MyAppTheme.ActionBar.TitleTextStyle" parent="TextAppearance.Sherlock.Widget.ActionBar.Title">
<item name="android:textColor">#fff</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">32sp</item>
<item name="textColor">#fff</item>
<item name="textStyle">bold</item>
<item name="textSize">32sp</item>
</style>

How to hide the element style in child style element?

I need to 'hide' the textSize parameter in BigButton style, inherited from Button. How to do so?
<style name="Button">
<item name="android:background">#color/button_background</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:padding">5dp</item>
<item name="android:textSize">#dimen/button_text_size</item>
</style>
<style name="BigButton" parent="#style/Button">
<item name="android:textSize"></item>
</style>
Try
<style name="BigButton" parent="#style/Button">
<item name="android:textSize">#null</item>
</style>

Categories

Resources