android:editTextBackground requires API level 11 (current min is 7) - android

I'm quite new to android. I created an application for api7 to api19 using support library and Theme.AppCompat.Light theme and I'm trying now to apply a custom theme to it but I get the error android:editTextBackground requires API level 11 (current min is 7) on the second line of themes_wvtheme.xml. I would like to know the correct edittext attribute for api<11.
This is my style.xml:
<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="#style/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>
This is my custom theme themes_wvtheme.xml:
<?xml version="1.0" encoding="utf-8"?>
<item name="android:editTextBackground">#drawable/wvtheme_edit_text_holo_light</item>
<item name="android:listChoiceIndicatorMultiple">#drawable/wvtheme_btn_check_holo_light</item>
<item name="android:listChoiceIndicatorSingle">#drawable/wvtheme_btn_radio_holo_light</item>
<item name="android:buttonStyle">#style/ButtonWVTheme</item>
<item name="android:imageButtonStyle">#style/ImageButtonWVTheme</item>
<item name="android:listChoiceBackgroundIndicator">#drawable/wvtheme_list_selector_holo_light</item>
<item name="android:activatedBackgroundIndicator">#drawable/wvtheme_activated_background_holo_light</item>

You can create a style for your EditTexts, and specify a background attribute for it. That is, in style.xml put something like:
<style name="Theme.MyApp.EditText" parent="#android:style/Widget.EditText">
<item name="android:background">#drawable/wvtheme_edit_text_holo_light</item>
<!-- ..other attributes.. -->
</style>
Then, in your app theme, add the line:
<item name="android:editTextStyle">#style/Theme.MyApp.EditText</item>
The oldest API level I've built for using this approach is 8, but it should work for API level 7 as well.

Related

How to change color to text of ActionBar's menu items?

I want to change the color of the text of menu items in the action bar. I' tried to change the theme but nothing works. I'm ussing API 19:
This is my res\values\styles.xml
<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="LoginFormContainer">
<item name="android:padding">28dp</item>
</style>
</resources>
Also the project generated styles.xml in res\values-v11\ res\values-v14\
I don't know if I have to change the theme or just set a property or something, any help I will really appreciate. Thank you!
Finally I found a solution to my problem. This is my final code:
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<!-- API 14 theme customizations can go here. -->
<item name="android:textAppearanceLargePopupMenu" >#style/m_textAppearanceLargePopupMenu</item>
<item name="android:textAppearanceSmallPopupMenu" >#style/m_textAppearanceSmallPopupMenu</item>
</style>
<style name="m_textAppearanceLargePopupMenu" parent="#android:style/TextAppearance.Holo.Widget.PopupMenu.Large">
<item name="android:textColor">#009ad2</item>
</style>
<style name="m_textAppearanceSmallPopupMenu" parent="#android:style/TextAppearance.Holo.Widget.PopupMenu.Small">
<item name="android:textColor">#009ad2</item>
</style>
</resources>
It is my res\values-v14\ file code.
I was confused, what I really wanted was to change the text color to the PopupMenu and it worked for me.
Thanks friends for your help!!
Check this Documentation in the section Customize the Text Color. It says the way you have to do it for the different android API levels.

Error Styling action Bar android

From manifest: min version 14
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
Style:
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.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>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowBackground">#color/fondoObscuro</item>
<item name="android:actionBarStyle">#style/OnTheGoActionBar</item>
</style>
<!-- general styles for the action bar -->
<style name="OnTheGoActionBar"
parent="#android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:titleTextStyle">#style/TitleTextStyle</item>
<item name="android:background">#color/actionBarObscura</item>
<item name="android:actionOverflowButtonStyle">#style/CustomOverflow</item>
</style>
I got the error no resource found, on both styles AppBaseTheme and OnTheGoActionBar
There is very specific reason for having two seperate values folder especially for `theming the app
See as you can see in the code you posted, I am sure that following code is from values\styles.xml
<style name="AppBaseTheme" parent="#android:style/Theme.Holo.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>
I would like to draw your attention to commented code
Theme customizations available in newer API levels can go in res/values-vXX/styles.xml
The styles.xml is for backward compatibility, you change the parent style
parent="android:Theme.Light" to parent="android:Theme.Holo.Light.DarkActionBar"
which is wrong since android:Theme.Holo.Light.DarkActionBar was introduced in API Level-14, See here Theme_Holo_Light_DarkActionBar Android docs. The Builder looks for Theme.Holo.Light.DarkActionBar , but it is not able to find it, as its applicable to new version and hence you see
I got the error no resource found, on both styles AppBaseTheme and OnTheGoActionBar
Simple move your code for custom styling to values-v14\styles.xml and everything will be fine, don't worry if you don't have style provided in values\styles.xml, untill and unless your minSdkVersion is 14.
I hope you understood it.

android:windowActionBarOverlay & android:actionBarStyle requires api level 11

I am making an android app and using android-support-v7-appcompat to make sure my app support action bars from android version 2.2 and up.
I need to make the Action Bar overlay and use a translucent background so I have modified the styles.xml to this code :
<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>
<!-- TRANSLUCENT THEME -->
<style name="TranslucentAB" parent="Theme.AppCompat.Light">
<item name="windowActionBarOverlay">true</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
<item name="actionBarStyle">#style/BlackBar</item>
</style>
<!-- TRANSLLUCENT COLOR STYLE -->
<style name="BlackBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#drawable/halfblack</item>
<item name="background">#drawable/halfblack</item>
</style>
</resources>
and modified manifest file to adapt the new ActionBar as :
android:theme="#style/TranslucentAB"
The problem is that the following two lines of code require API level 11 and up :
<item name="android:windowActionBarOverlay">true</item>
<item name="android:actionBarStyle">#style/BlackBar</item>
but I need to support from API level 8 and up. If I remove these two lines the app runs fine on Android 2.2 with black translucent action bar. But if I run the app in Android 4.3 the app launches with a solid white action bar. halfblack is just a png file in drawable folder with 70% black color.
Found solution to my problem :
I have to make separate styles.xml in res/values-v11 to support the same functionality in android 3.0 and up
To use the action bar overlay with the support library, do this:
<!-- Support library compatibility -->
<item name="windowActionBarOverlay">true</item>
Notice how the style name does not include the android: prefix.

ActionBar appearing in different colors with different versions of Android

I know the question seems simple, but not anything like chei here before. So there you go:
In my android application using the Support Library with AppCompat v7, added an ActionBar. Everything works perfectly, except that when the application runs on android 2.3, the background of the ActionBar is dark, and when the squeegee android 4.0.2 ActionBar this background turns gray.
Below is how to define my #style
<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="#style/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>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
how can I solve this?
This will not work for you on min target as 2.3.3 in case your min target is API level 11 you can change the background color
<resources>
<style name="AppTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">ANY_HEX_COLOR_CODE</item>
</style>
</resources>
I would like to add my observation (using min sdk 8, target sdk 19) for the future readers on this issue.
If you want to set just the background color of the action bar across different android versions, its easier to do it in code.
actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable( getResources().getDrawable(R.color.your_desired_color));
This overrides the default background across versions and set your desired color.
Note: I had seen on various post and tried to set the background color as follows:
ColorDrawable colorDrawable = new ColorDrawable();
colorDrawable.setColor(R.color.your_desired_color);
actionBar.setBackgroundDrawable(colorDrawable);
but it did not work, reason unknown to me for the time being.so I successfully tried the code mentioned above.
if you want to set the background color of the action bar (along with other attributes) not in code, you can use style and theme. I had done the styling as follows.
inside res/values/style.xml
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations 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>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
inside res/values-v11 and res/values-v14
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- API 11 theme customizations 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>
<!-- custom theme for my app -->
<style name="MyAppTheme" parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/bgcolor</item>
</style>
</resources>
Note:
As I had to have similar look for the action bar across android versions, I had copy-pasted the code in res/values-v11 and res/values-v14 from res/values. But to my surprise,I did not get the desired result. Reason? We need to add the "android" namespace before the tags for android v11 and later. So I changed actionBarStyle to android:actionBarStyle and background to android:background. That brought me the desired result.

Android / how to best define themes / values

I am trying to figure out the best way to pick best themes for new and old Android versions, e.g. by reading this Trying to use holo theme in Android not working where they define Holo in values-11 and Black in values
Black
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Black" />
</resources>
Holo
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.MyTheme" parent="#android:style/Theme.Holo" />
</resources>
Question 1)
Will that work no matter what minSdkVersion setting I use? I guess that Android for never versions will assume values-11 is better match than values.fallback when no specific folder matches
Question 2)
Assuming above (which I think is the case), how/where do I best define my MyTheme extensions. Suppose I have:
<style name="MyTheme2" parent="MyTheme">
<item name="android:windowTitleSize">44dip</item>
<item name="android:windowTitleBackgroundStyle">#style/MyWindowTitleBackground</item>
</style>
<style name="MyWindowTitleBackground">
<item name="android:background">#android:color/transparent</item>
<item name="android:padding">0px</item>
</style>
Do I have to duplicate that in both values styles.xml files? Or can I somehow place that in a shared folder? From my understand, I don't think that is possible?
I am new to Android, so I am just trying to figure out what would be the best thing to do :)
Independent customization should be created in values/styles. Follow this template: (ANDROID DEFAULT)
In values/styles
<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="#android:style/Theme.Black">
<!--
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>
</resources>
In values-v11/styles
<resources>
<!--
Base application theme for API 11+. This theme completely replaces
AppBaseTheme from res/values/styles.xml on API 11+ devices.
-->
<style name="AppBaseTheme" parent="#android:style/Theme.Light.NoTitleBar">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>

Categories

Resources