Experimenting with styles => No resource found that matches the given name: attr - android

I try to develop an app for API 8 but do not have any experience with styles.xml. For activities in the app I use Theme.Light. After playing with styles I got the error above. I've also checked other posts on this portal and I tried many suggestions but I could not get further. The styles.xml is below and hopefully someone will come with suggestions.
<resources>
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="ContactLabelTextView">
<item name="layout_width">wrap_content</item>
<item name="layout_height">wrap_content</item>
<item name="layout_gravity">left|center_vertical</item>
<item name="layout_marginLeft">15dp</item>
<item name="layout_marginRight">5dp</item>
<item name="layout_marginTop">5dp</item>
<item name="clickable">false</item>
<item name="longClickable">false</item>
<item name="textSize">14sp</item>
<item name="textAppearance">?android:attr/textAppearanceMedium</item>
<item name="android:textColor">#android:color/black</item>
<item name="layout_marginBottom">5dp</item>
</style>
<style name="ContactMultiplineText" >
<item name="layout_width">match_parent</item>
<item name="layout_height">wrap_content</item>
<item name="layout_marginLeft">15dp</item>
</style>

After reading the post recommended by Alexander Zhak I have better understanding of styles. Therefore, I made some modifications to my styles.xml and it works. Those modifications are:
...
<style name="ContactLabelTextView" parent="#android:style/TextAppearance.Medium">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#android:color/black</item>
<item name="android:longClickable">false</item>
<item name="android:clickable">false</item>
</style>
<style name="ContactLabelTextView.Layout">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">left|center_vertical</item>
<item name="android:layout_marginLeft">15dp</item>
<item name="android:layout_marginRight">5dp</item>
<item name="android:layout_marginTop">5dp</item>
<item name="android:layout_marginBottom">5dp</item>
</style>
<style name="ContactMultiplineText">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_marginLeft">15dp</item>
</style>
...

You need to have a parent style to enable you to call the attributes of it.
sample:
<style name="ContactLabelTextView" parent="#android:style/TextAppearance.Medium">
The above code is used when you want your textView as a Medium size text, you can still change it what ever size you want for your TextView.

Related

Wrong colors on pre-lollipop devices with AppCompatTheme

I have this in my style.xml file
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
<!--<item name="colorPrimary">#color/colorPrimary</item>-->
<!--<item name="colorAccent">#color/colorAccent</item>-->
<item name="android:windowBackground">#color/white</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="LoginScreenTheme" parent="AppTheme">
<item name="android:textColor">#color/white</item>
<item name="colorAccent">#color/white</item>
<item name="colorPrimaryDark">#color/login_background_dark</item>
</style>
<style name="LoginEditTextTheme" parent="AppTheme">
<item name="colorControlNormal">#color/login_edit_text_hint_color</item>
<item name="colorControlActivated">#color/login_edit_text_accent</item>
<item name="colorControlHighlight">#color/login_edit_text_accent</item>
<item name="android:textColorHint">#color/login_edit_text_hint_color</item>
<item name="android:textColorPrimary">#color/white</item>
</style>
<style name="LoginErrorFloatingLabelTheme" parent="TextAppearance.AppCompat.Small">
<item name="android:textColor">#color/login_error_floating_label_color</item>
</style>
<style name="ActionBarTheme" parent="AppTheme">
<item name="android:background">#color/home_primary_color</item>
</style>
<style name="LoginWaitingProgressBar" parent="AppTheme">
<item name="colorAccent">#color/orange_light</item>
</style>
</resources>
On devices with Lollipop and upper everything is alright, but on pre-lollipop there are wrong colors. It's look like theme is not applied to the devices with pre-lollipop android version. After googling I found that people are adviced to remove 'android:' prefix before every item in AppCompat theme but it doesn't work for me coz android studio doesn't see items after that.
The reason was that I didn't extend AppCompatActivity. When I changed it everything became okay.
colorPrimary , colorPrimaryDark and colorAccent items are available on only API 21+.If you want to apply them on pre lollipop devices you must move your current styles.xml file to values-v21 and create a new styles.xml on values folder and use the correct item for pre lollipop.
Check out android developers for more https://developer.android.com/guide/topics/ui/themes.html

Unable to customize ActionBar Tabs for API-23

I'm working on a application in which I am having Tab Bars. I am assigning a custom theme to my tabs using styles.xml present in values-v23 folder. But the thing is that I am not able to achieve my custom theme every time I'm launching the application. I can't understand where is the problem. I am sharing my style.xml file here to make you understand this better.
styles.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<style name="AppThemeWhite" parent="AppBaseTheme">
<item name="android:windowIsTranslucent">false</item>
<item name="android:windowBackground">#color/white</item>
<item name="android:textColor">#color/black</item>
<item name="android:editTextStyle">#style/BlackEditText</item>
<item name="android:actionBarTabTextStyle">#style/CustomActionBarTabs_TextColor</item>
<item name="android:actionBarTabStyle">#style/CustomActionBarTabs</item>
<item name="android:actionBarTabBarStyle">#style/CustomActionBarTabBar</item>
</style>
<!-- action bar tab styles -->
<style name="CustomActionBarTabs_TextColor" parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#666666</item>
<item name="android:textSize">14sp</item>
<item name="android:typeface">sans</item>
</style>
Here I'm trying to change the text color of Tab titles by using the #style/CustomActionBarTabs_TextColor property but nothing is happening. Can someone please help to solve this one.
Any help would be appreciable.
Thanks.
you can apply following style to your tab layout
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabIndicatorColor">#color/indicatorcolor</item>
<item name="tabIndicatorHeight">4dp</item>
<item name="tabTextAppearance">#style/MyCustomTabTextAppearance</item>
<item name="tabSelectedTextColor">#color/seltextcolor</item>
</style>
<style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#000000</item>
<item name="textAllCaps">true</item>
</style>

How to align the Action bar Tab text in android

You can check out my output below.There you can see, In ANNOUNCEMENT,letter T is placed at bottom.It needs to be align like Gallery and placed in the center.
styles.xml:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
<style name="GridLayout">
<item name="android:drawSelectorOnTop">true</item>
<item name="android:listSelector">#drawable/photogrid_list_selector</item>
</style>
<style name="CustomRatingBar" parent="#android:style/Widget.RatingBar">
<item name="android:progressDrawable">#drawable/custom_ratingbar</item>
<item name="android:minHeight">20dip</item>
<item name="android:maxHeight">20dip</item>
</style>
<style name="CustomTheme" parent="#android:style/Theme">
<item name="android:tabWidgetStyle">#style/CustomTabWidget</item>
</style>
<style name="CustomTabWidget" parent="#android:style/Widget.TabWidget">
<item name="android:textAppearance">#style/CustomTabWidgetText</item>
</style>
<style name="CustomTabWidgetText"
parent="#android:style/TextAppearance.Widget.TabWidget">
<item name="android:textSize">12sp</item>
<!-- <item name="android:textStyle">bold</item> -->
</style>
</resources>
I doesn't know how to solve these issue.Anybody can help me if you know how to solve these.Thank you.
I just tried it almost two days.But I can't find a solution for
these.After that I think and solve these problem.
Actually I am using an emulator.So that these kind of problems
occurred for me.
Then I try to run these code in Real devices.It seems Action bar
Tab test Announcement align at the centre.Problem solved for me.

Common styles for v10 and v11+?

I'm using the v7 support library in order to have an ActionBar on API Level 10+ (that's Android 2.3.3+). Now, I want to customize the look a bit, so I added an application theme. Excerpt of my values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
</style>
This works fine on Android 2.3.3, where the compat stuff is used. However, on Android 4.3 on an N4 (or an emulator), the styles are not applied. If I change the styles.xml file to:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
(notice the added android: prefix) it works on 4.3, but doesn't on 2.3 (styles not applied).
Is there any way I can get around this without specifying each <item> twice, once with the prefix and once without?
There is a perfect example on the google docs site:
http://developer.android.com/guide/topics/ui/actionbar.html#StyleExample
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
<item name="actionBarTabTextStyle">#style/TabTextStyle</item>
<item name="actionMenuTextColor">#color/actionbar_text</item>
</style>
<!-- general styles for the action bar -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:backgroundStacked">#drawable/actionbar_background</item>
<item name="android:backgroundSplit">#drawable/actionbar_background</item>
<!-- Support library compatibility -->
<item name="titleTextStyle">#style/TitleTextStyle</item>
<item name="background">#drawable/actionbar_background</item>
<item name="backgroundStacked">#drawable/actionbar_background</item>
<item name="backgroundSplit">#drawable/actionbar_background</item>
</style>
<!-- action bar title text -->
<style name="TitleTextStyle"
parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- action bar tab text -->
<style name="TabTextStyle"
parent="#style/Widget.AppCompat.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
</resources>
Is there any way I can get around this without specifying each <item>
twice, once with the prefix and once without?
Another way would be to create version specific res/values-XX folders.
Since the divide is version 10 and versions 10+, you can create res/values-v10/styles.xml containing:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="background">#drawable/bg_actionbar</item>
</style>
Let versions 10+ deal with the default res/values/styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
</style>
Still, it isn't much different from specifying <item></item> twice.
For reference, you can look at the project structure of ActionBarSherlock. That should provide you some pointers.
You can also take a look at: Applying Styles and Themes to the UI. Scroll down to sub-section Select a theme based on platform version.
If I have not misunderstand your issue, you can collapse it together this way
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/ActionBarStyle</item>
<item name="actionBarStyle">#style/ActionBarStyle</item>
</style>
<style name="ActionBarStyle" parent="#style/Widget.AppCompat.ActionBar">
<item name="android:background">#drawable/bg_actionbar</item>
<item name="background">#drawable/bg_actionbar</item>
</style>
In my experience, this way eclipse gives compile time errors every time you change somethings inside styles.xml (due of lint if I remember good), but clean and rebuild make those errors go away.

How I can change the style of a down ActionBar?

I'm using ActionBarSherlock, and my app will install on many kinds of smartphones, and for the small smartphones I divide the actionbar with:
android:uiOptions="splitActionBarWhenNarrow"
My problem appear when the bar is split, because the style only is maintained on the top bar (green), but not on the button bar (gray) :P
Here a screenshot:
And my current style:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Light">
<!--
Theme customizations available in newer API levels can go in
res/values-vXX/styles.xml, while customizations related to
backward-compatibility can go here.
-->
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.Sherlock.Light">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:textViewStyle">#style/label</item>
<item name="android:checkboxStyle">#style/checkbox</item>
<item name="android:buttonStyle">#style/boton</item>
<item name="android:starStyle">#style/star</item>
<item name="actionBarStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.Styled.ActionBar</item>
<!-- Agregamos algunos estilos para ver como cambiar los colores de la barra -->
<item name="android:actionDropDownStyle">#style/Widget.Styled.ActionBar</item>
<item name="actionDropDownStyle">#style/Widget.Styled.ActionBar</item>
<item name="actionBarSplitStyle">#style/Widget.Styled.ActionBar</item>
<item name="android:actionBarSplitStyle">#style/Widget.Styled.ActionBar</item>
</style>
<style name="label" parent="android:style/Widget.TextView">
<item name="android:padding">4dp</item>
<item name="android:textColor">#DF0101</item>
<item name="android:textSize">20sp</item>
</style>
<style name="checkbox" parent="android:style/Widget.CompoundButton.CheckBox">
<item name="android:textColor">#DF0101</item>
<item name="android:textSize">20sp</item>
</style>
<style name="boton" parent="android:style/Widget.Button">
<item name="android:background">#drawable/btn_form</item>
<item name="android:textColor">#ffffff</item>
<item name="android:textSize">20sp</item>
</style>
<style name="star" parent="android:style/Widget.CompoundButton.Star">
<item name="android:textColor">#DF0101</item>
<item name="android:textSize">20sp</item>
</style>
<style name="Widget.Styled.ActionBar"
parent="Widget.Sherlock.Light.ActionBar.Solid.Inverse">
<item name="background">#drawable/background</item>
<item name="android:background">#drawable/background</item>
<item name="android:backgroundStacked">#drawable/background</item>
<item name="android:backgroundSplit">#drawable/background</item>
<item name="android:actionButtonStyle">#drawable/background</item>
</style>
</resources>
What is the name of this component, in order to add it to the style sheet?
My problem was I forgot to put this parameter:
<item name="backgroundSplit">#drawable/background</item>
Only had placed this:
<item name="android:backgroundSplit">#drawable/bg_actionbar</item>
Sorry :P

Categories

Resources