Reference a style without "#" symbol? - android

i have this code:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/primary_color</item>
<item name="colorPrimaryDark">#color/primary_dark_color</item>
<item name="actionBarStyle">#style/MiwokAppBarStyle</item>
<item name="android:windowContentOverlay">#null</item>
</style>
<!-- App bar style -->
<style name="MiwokAppBarStyle" parent="style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<!-- Remove the shadow below the app bar -->
<item name="elevation">0dp</item>
</style>
<!-- Style for a tab that displays a category name -->
<style name="CategoryTab" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#android:color/white</item>
<item name="tabSelectedTextColor">#android:color/white</item>
<item name="tabTextAppearance">#style/CategoryTabTextAppearance</item>
</style>
<!-- Text appearance style for a category tab -->
<style name="CategoryTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textColor">#A8A19E</item>
</style>
</resources>
why in MiwokAppBarStyle we don't use # symbol in referencing the parent style like this parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse" ?, and why we referencing parent style using style/ insted of referencing without style/ prefix like parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse" ??

Related

How to capitalize button text pre-Lollipop?

I tried using adding it into styles.xml like so:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
<!-- buttons will not have shadows -->
<item name="android:buttonStyle">#style/Widget.AppCompat.Button.Borderless</item>
<item name="android:textAppearanceButton">#style/DefaultButtonTextStyle</item>
<item name="android:colorBackground">#android:color/white</item>
</style>
<!--The button text style to be used throughout the app-->
<style name="DefaultButtonTextStyle" parent="#style/Base.TextAppearance.AppCompat.Button">
<!-- Ensure that the buttons are all caps even pre Lollipop-->
<item name="android:textAllCaps">true</item>
<item name="textAllCaps">true</item>
</style>
You only need to create a custom style for your button
<style name="CustomButton">
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_centerVertical">true</item>
<item name="android:textAllCaps">true</item>
</style>
Then set it to your button like:
<Button
android:id="#+id/total_bill"
style="#style/CustomButton" />
Or you can do something like:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="buttonStyle">#style/MyButton</item>
</style>
<style name="MyButton" parent="Widget.AppCompat.Button">
<item name="android:textAllCaps">true</item>
</style>
The second method will change it for all Button across the application.One another way is to extend the Button and create a custom Button where textcaps is set to true and use that Button instead of default one.

How to change ActionBar Colour

I am trying to change my App ActionBar colour to no success. I am using the this library https://github.com/neokree/MaterialNavigationDrawer;
Here is the style.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="colorControlActivated">#color/color_c</item>
<item name="toolbarStyle">#style/Widget.Toolbar</item>
</style>
<style name="Widget.Toolbar" parent="#style/Widget.AppCompat.Toolbar">
<item name="contentInsetStart">5dp</item>
</style>
<style name="AppTheme.ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/color_a</item>
<item name="background">#color/color_a</item>
<!-- Support library compatibility -->
</style>
<style name="FullscreenTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowBackground">#null</item>
</style>
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">
<item name="colorPrimary">#color/color_a</item>
<item name="colorPrimaryDark">#color/color_a</item>
<item name="colorAccent">#FFFFFF</item>
<item name="rippleBackport">true</item>
<item name="singleAccount">true</item>
<item name="multipaneSupport">true</item>
<!--<item name="learningPattern">false</item>-->
</style>
<style name="MySubheaderTheme">
<item name="subheaderTitleColor">#000000</item>
</style>
<style name="MySectionTheme" >
<item name="sectionColorIcon">#000000</item>
<item name="sectionColorText">#000000</item>
<item name="sectionColorNotification">#000000</item>
<item name="sectionBackgroundColorPressed">#160000FF</item>
<item name="sectionBackgroundColorSelected">#0A0000FF</item>
<item name="sectionBackgroundColor">#000000FF</item>
</style>
</resources>
I use the MyNavigationDrawerTheme theme for my activities.
You should be able to set the action bar color using the android:colorPrimary attribute:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
</style>
</resources>
Based on information here
You should create your styles also for v21 and above with a small change (because they natively support material theme).
And in values-v21/style.xml add android:colorPrimary and others attributes with android: prefix to your style:
<style name="MyNavigationDrawerTheme" parent="MaterialNavigationDrawerTheme.Light.DarkActionBar">
<item name="android:colorPrimary">#color/color_a</item>
<item name="android:colorPrimaryDark">#color/color_a</item>
<item name="android:colorAccent">#FFFFFF</item>
<!--...-->
</style>

Backward compatibity using v-21/styles.xml not working

I am trying to style my button while maintaining backwards compatibility.
I have 2 files as follows:
values/styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="android:buttonStyle">#style/RoundedButton</item>
</style>
<style name="RoundedButton" parent="#style/Widget.AppCompat.Button">
</style>
<style name="AppName.NoActionBar" parent="AppTheme" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="DemoButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minWidth">40dp</item>
</style>
</resources>
values-v21/styles.xml:
<resources>
<style name="RoundedButton" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/btn_rounded</item>
</style>
</resources>
But even then my button looses all attributes i.e. just a text is displayed as per android-studio's "XML preview". I just want the button to default to the usual Holo theme on pre-lolipop devices. It works as expected on Lolipop devices.
What am I doing wrong?
In values/styles.xml
<style name="RoundedButton" parent="#style/Widget.AppCompat.Button">
</style>
change it to as Follow :-
<style name="RoundedButton" parent="android:Widget.Holo">
</style>
I couldn't figure out the reason of why this was happening so I removed the line <item name="android:buttonStyle">#style/RoundedButton</item> from my values/styles.xml file, and added it to my values-v21/styles.xml.
I do not like this solution as there is a lot of code duplication. The only good thing about it is that it works.
Now my files look like:
values/styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
</style>
<style name="AppName.NoActionBar" parent="AppTheme" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="DemoButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minWidth">40dp</item>
</style>
</resources>
v21/styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="colorAccent">#color/accent</item>
<item name="android:textColorPrimary">#color/primary_text</item>
<item name="android:textColorSecondary">#color/secondary_text</item>
<item name="android:buttonStyle">#style/RoundedButton</item>
</style>
<style name="RoundedButton" parent="Widget.AppCompat.Button">
<item name="android:background">#drawable/btn_rounded</item>
</style>
<style name="AppName.NoActionBar" parent="AppTheme" >
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="DemoButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:minWidth">40dp</item>
</style>
</resources>

can we set actionbar height manually in android theme.light

I am using "Theme.Light" theme for my android project and while setting up a navigation drawer how can i set actionbar size(height).
I used the below code and i got an error..
<style name="Theme.Light.ActionBar" parent="#android:style/Theme.Light">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="actionBarSize">36dip</item>
<item name="android:windowActionBarOverlay">true</item>
</style>
can you please reply to my problem as soon as possible and thank you.
Use height attribute,for actionBarHeight
<item name="android:height">#dimen/bar_height</item>
you have to create style like this:
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="colorPrimary">#color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<!-- native widgets will now be "tinted" with accent color -->
<item name="colorAccent">#color/accent</item>
<!--Action bar style-->
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
<item name="actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:titleTextStyle">#style/AppTheme.ActionBar.TitleText</item>
<item name="android:height">#dimen/bar_height</item>
</style>
<style name="AppTheme.ActionBar.TitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textSize">#dimen/bar_text_size</item>
<item name="android:textColor">#color/bar_text_color</item>
</style>
you have to try below code :
<resources>
<style name="Theme.FixedSize" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<item name="actionBarSize">48dip</item>
<item name="android:actionBarSize">48dip</item>
</style>
</resources>
If you are using AppCompat, you can set the "actionBarSize" attribute in your theme (which must inherit from Theme.AppCompat.x). You can also use a Toolbar in your layout and set its layout_height to the desired value.

Android: Error retrieving parent for item in style

in my res/values/styles.xml file i get this error:
Error retrieving parent for item: No resource found that matches the given name '#style/
Widget.Holo.ActionBar'.
in my android manifest i have made the minsdkversion="11" and targetsdkversion="18"
i do not know what the problem is. Here is the xml file
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#android:style/Theme.Holo">
<item name="android:windowActionBarOverlay">true</item>
</style>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="#style/TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
parent="#style/Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
// try this
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="android:Theme.Holo">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="android:Widget.Holo.ActionBar">
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
parent="android:Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
**colors.xml** // define here color which are use in your style
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="actionbar_text">#yourcolorcode</color>
</resources>

Categories

Resources