change android:Theme.Light to Theme.AppCompat.Light.DarkActionBar - android

i have app which was created in android:Theme.Light. i want to change it to Theme.AppCompat.Light.DarkActionBar but i get
no resource found that matches the given name
'theme.appcompat.light.darkactionbar'
I have android-support-v4.jar, when i try add appcompat_v7 i get errors in codes where is something like it R..... Can I add DarkActionBar to this project without problems with codes? Without changes in code?
I have:
<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: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>
</resources>
I want:
<resources>
<!--
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.DarkActionBar">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>

Ensure that your application is properly linked with the Support Library, with resources (see documentation here).
And don't forget #style/:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
This will prevent the no resource error from occurring.
You might be interested in this tutorial too.

If you're doing this in your manifest, do the following to set the theme for the whole app:
<application
...
android:theme="#style/Theme.AppCompat.Light.DarkActionBar"
...>
in your XML for the specific theme, you need #style, so put the following:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">

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.

Android Theme.Holo not working

i am trying to get my app to use the theme "Theme.Holo", which is the dark theme for android. my app minimum SDK is 9, and i have the Support libraries included from google.
i had my app working with the dark theme, and i have no idea what i changed, now its only light. and ic ant seem to change it.
this was my button before (i want this):
And this is what i have now:
This is my values/res/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="android:Theme">
<!--
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>
and this is my res/values-11/styles.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="#android:style/Theme.Holo">
<!-- API 11 theme customizations can go here. -->
</style>
</resources>
and res/values-14/styles.xml
<resources>
<!--
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="#android:style/Theme.Holo">
<!-- API 14 theme customizations can go here. -->
</style>
</resources>
Manifest part that relates to theme,
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
At this point i have no idea why the buttons are showing up as Light theme, i tried Theme.Black as well, it didn't change anything.
as #FD_ pointed out Holo theme is available on ICS and above. I suppose the emulator/device you are testing against has SDK < 11.
If you need backward compatibility for holo theme use HoloEveryWhere library by Prototik.
To use Theme.Holo you have to use at least API Level 11. Please refer this link in the Android Developer Guide.
Try to change the minimum API-Version to 11 in you Android Manifest and it should work.

Android set default device theme

I've an app which may be ran from 2.2 to 4.x devices.
When I run this app on 4.x it looks cool, holo style. But when I run it on older devices, it seems to be so much "lighty".
There's a screenshot so you can compare:
This is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
And my 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:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
It's obvious that holo doesn't exist in 2.3, but then it should render its default device theme, right?
So the input is correct, but the TextView looks too grey.
Any idea?
As someone suggested, I finally created a new folder:
res/values-v11/
On this folder, I've put a file named styles.xml, which is the following:
<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:Theme.Holo.Light.NoActionBar.Fullscreen">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
And the folder res/values/ which will be called for android with api lower than 11, contains a styles.xml and there I've changed the parent template, like this:
<!--
Base application theme, dependent on API level. This theme is replaced
by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
-->
<style name="MyTheme" parent="#android:style/Theme.Light">
</style>
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
This ends up like this:
Devices with api higher than 11 -> holo theme
The rest: Theme.Light ("Normal theme")

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>

I want to put small line inside each EditText

I want to add small lines under the Edit Texts like the following , How can I do that ?
This is by default look of Edittext in Holo Theme. so just apply Holo Theme.
if you want to apply Holo Theme. set
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="17" />
and styles.XML inside values-v11 folder
<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:Theme.Holo.Light">
<!-- API 11 theme customizations can go here. -->
</style>
and styles.XML inside values folder
<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:Theme.Light.NoTitleBar">
<!--
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="progressbar_holo" parent="#android:style/Theme.Light">
</style>
and in AndroidMeanifeast.xml
android:theme="#style/AppTheme"
in application TAG.

Categories

Resources