When I change locale, whole theme is changed - android

This is so weird.
The best way is to show you a picture:
I've not set any theme or anything like that, so the default one should be used...
Any idea?
Edit: It's the same device!! An android 4.2 emulator.
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="es.triiui.myapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="es.triiui.myapp.Activity_EditDetails"
android:label="#string/title_activity_activity__edit_details" >
</activity>
<activity
android:name="es.triiui.myapp.AddNewEntry"
android:label="#string/title_activity_add_new_entry" >
</activity>
<activity
android:name="es.triiui.myapp.ShowDetails"
android:label="#string/title_activity_show_details" >
</activity>
<activity
android:name="es.triiui.myapp.Setpassword"
android:label="#string/title_activity_setpassword" >
</activity>
</application>
(values/styles.xml) is:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
(values-ca/styles.xml) is:
<resources>
<style name="AppBaseTheme" parent="android:Theme.Light">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
</resources>
Both are exactly the same.
Any idea?

Those XML resources you posted are wrong.
In general, themes go in themes.xml (but that shouldn't matter since they're just a style) but more importantly, you don't have a closing </resources> tag (copy/paste error?), nor a namespace definition (xlmns attribute on <resources>).
Both of these should trigger AAPT errors (the missing close tag definitely, the namespace, I'm not sure about - it definitely triggers an Android Lint error!).
Try removing the values-ca/styles.xml file. It will default to values/styles.xml and you shouldn't see any visual changes.

I've not set any theme or anything like that, so the default one
should be used...
From the documentation of android:theme:
If this attribute is not set, the activity inherits the theme set for
the application as a whole — from the <application> element's theme
attribute. If that attribute is also not set, the default system theme
is used
So since you didn't specify a theme it will use the devicedefault theme, therefore the left device uses the holo theme and the right one the pre HC theme.

Related

How to solve it: “You need to use a Theme.AppCompat theme (or descendant) with this activity”

View imageOverlayView =
LayoutInflater.from(getApplicationContext()).
inflate(R.layout.layout_image_overlay, null);
new ImageViewer.Builder(getApplicationContext(), imageURLs)
.setStartPosition(0)
.hideStatusBar(false)
.setOverlayView(imageOverlayView)
.show();
I'm using this ImageView builder to load images in fullscreen view, but I get the above mentioned error while compiling.And the activity which I'm using extends from AppCompatActivity. Also I tried the activity extending from Activity too, its not working.
Thank you very much for your time and assistance in this matter.
The error:
You need to use a Theme.AppCompat theme (or descendant) with this activity
means that you need to use a style for the activity which is derived from AppCompat theme. It is usually in res/values/styles.xml. If you don't have create it to something like this:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
</resources>
Then, use it for your activity by adding it to AndroidManifest.xml with android:theme="#style/AppTheme" (please read the comment):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.testcode">
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<!-- Or you can use specific theme for the activity -->
<activity
android:name=".anotherActivity"
android:label="#string/app_name" >
android:theme="#style/AppTheme" >
</activity>
</application>
</manifest>
.hideStatusBar(false)
is creating your issue.
You have to make sure that the AppTheme has a defined Status and Toolbar and the Activity uses the Theme.
By default Android Studio generates the base theme.
You used AppCompat as the theme in the code section (that hideStatusBar), but you used another theme in the manifest or style.xml. Not consistent as you use different themes in two places So it says you need to use it.

Change background color of actionBar [duplicate]

I've a newly created project and the first thing I want to do is add and style an action bar. I made it the way they tell in their official tutorials and even tried some other ways but I just can't make it work.
After many tries, I decided to do something really basic but even like that I can't make it work.
This is what I have:
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/ActionBar</item>
</style>
<style name="ActionBar" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/blue</item>
</style>
manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
Another question is what is the difference between the #android:style/Theme.Holo, #style/Theme.AppCompat.Light.DarkActionBar or simply Theme.AppCompat.Light.DarkActionBar?
Thanks.
Per the Using the Material Theme training, the Material theme (and AppCompat theme's which backport / use Material theming) use colorPrimary to color the action bar. Therefore your theme can be:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#color/blue</item>
</style>
You'll find more details on how to theme using AppCompat / Material in the AppCompat v21 blog post and in this pro-tip
I recommend you use this tools to generate ActionBar styles:
http://jgilfelt.github.io/android-actionbarstylegenerator/
Good Luck!

Holo theme in android makes application stop 'unfortunately'

so I'm trying to style my application, and I've run into problems when using the Holo theme. I have no intrest in earlier versions of android, so I'don't want to use AppCompat.
To do my error checking I have created an empty app with one blank activity. This is my styles.xml:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="#android:style/Theme.Holo.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="android:actionBarStyle">#style/AppTheme_ActionBarTheme</item>
</style>
<style name="AppTheme_ActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/light_green</item>
<item name="android:titleTextStyle">#style/AppTheme_ActionBarTheme_Text</item>
</style>
<style name="AppTheme_ActionBarTheme_Text" parent="AppTheme_ActionBarTheme">
<item name="android:textColor">#color/light</item>
</style>
</resources>
and this is my AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fokamb.chmielowskim.fokamb" >
<uses-sdk android:targetSdkVersion="15" android:minSdkVersion="14"/>
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/AppTheme"
>
<activity
android:name=".MainActivity"
android:label="#string/main_act_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I didn't change any other files, and I tried running this app on an emulator with API level 21 and my phone with api 19. On both, i get the message "Unfortunately, FokaMB has stopped"
Even though, in the preview window in android studio the app looks the way I would've liked it to.
So, where might be my mistake? If I use AppCompat app works fine, but im unable to change the text color of actionbar (even though the background changes). Any help would be greatly appreciated:)

App is not using custom theme

i want to disable the ActionBar in my application, I have been looking for a solution on stackoverflow for quiet a while but nothing helped. My problem is that my custom-theme "NoActionBar" is not used, instead it keeps using "AppBaseTheme" although I changed it in the manifest:
android:theme="#style/NoActionBar"
values-v14 styles:
<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>
<style name="NoActionBar" parent="AppBaseTheme">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
same with values-v11. In values i added this line but I think its not neccessary:
<style name="NoActionBar" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
I tried to change the parent of NoActionBar, didn't work. I tried to create an extra .xml for "NoActionBar" but that didn't work either because the manifest didn't find it. I tried other tipps from stackoverflow questions but they're pretty outdated.
I know when i put the two "items" within the "AppBaseTheme"-style it works, but I'm pretty sure that is not the proper way to use it?
In a nutshell:
Can somebody please explain to me why its not using my theme? What theme needs which parent? (How would I define multiple themes?)
I hope I explained it properly, I assume the answer is rather simple, sorry in advance for my language mistakes, I'm not native. Thanks!
Edit Manifest:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="21" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/NoActionBar" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
You are using your theme but your parent can't be AppBaseTheme, you have to use as parent for example Theme.Holo.NoActionBar or at least a style without action bar.

Remove app title bar android

I know this question has been asked million times but whichever method I use is not good for me.
If I use
android:theme="#android:style/Theme.NoTitleBar"
in the manifest file, the whole theme of the app changes. If I put
requestWindowFeature(Window.FEATURE_NO_TITLE);
in the onCreate activities, it shows up shortly when starting an app.
Btw I don't have any theme selected, just using standard android.
It is unclear what you mean by "whole theme of app changes". For API Level 11+ devices, you probably should be using #android:style/Theme.Holo.NoActionBar.
If you add the theme to the application, it applies to the whole app.
android:theme="#android:style/Theme.NoTitleBar"
You have to add it to the activity declaration.
<activity
android:name=".YourActivity"
android:theme="#android:style/Theme.NoTitleBar"/>
To remove the title bar from your app in android studio
Open res > values > styles.xml file
Replace your code with:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
Open your style.xml file, create a new style just like below.
You choose your own name and set the parent as below
<style name="your_own_name" parent="Theme.AppCompat.Light.NoActionBar">
</style>
In your AndroidManifest.xml file, set the theme name for the specific activity you dont want the bar to show and you are done
<activity android:theme ="#style/your_own_name" >
</activity>
This is what worked for me
android:theme="#style/Theme.AppCompat.NoActionBar">
when you create a new project in android then you will get default theme applied on your project, that has title bar. but if you want to remove or apply some other theme for your whole App then you can define like below at application level:
<application
android:name="com.mycomp.myproj.MainApplication"
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
but if you want to apply some theme only at some specific screens then you can define like below at activity level:
<activity
android:name="com.mycomp.myproj.MainActivity"
android:label="#string/app_name"
android:theme="#style/AppTheme">
For android 8 and above support. Use this in your app theme file. I've modified my default in res/styles.xml :
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:background">#color/white</item>
</style>
Inside AndroidManifest
<activity
android:name=".activity.HomeMenu"
android:screenOrientation="nosensor"
android:theme="#android:style/Theme.Light.NoTitleBar">
<intent-filter>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and make sure your Class extends to Activity
If you have made a custom theme in styles.xml you can do this:
<style name="AppTheme" parent="android:Theme.Material.Light">
<!-- Override the android colour scheme etc. -->
<item name="android:colorPrimary">#color/color_primary</item>
</style>
To remove the Action bar and title add to styles.xml:
<style name="AppTheme.NoActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
Then in your AndroidManifest.xml you can use your custom theme with or without the action bar
<application
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme"> <---- With action bar
<activity
android:theme="#style/AppTheme.NoActionBar"> <---- No action bar
<intent-filter>
etc...

Categories

Resources