Currently working on migrating to ActionBar in the support libraries. Currently trying to migrate my old themes to inherit from Theme.AppCompat.Light.DarkActionBar but it isn't going very smoothly.
It is fine if I apply the theme in the manifest as such:
<activity
android:name="com.fitsby.LoginActivity"
android:screenOrientation="portrait"
android:theme="#style/Theme.AppCompat.Light.DarkActionBar" >
</activity>
But I get a runtime error, stating that LoginActivity(subclass of ActionBarActivity) must have a theme which inherits from Theme.AppCompat, when I do the following:
in styles.xml:
<style name="AppTheme" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:typeface">sans</item>
</style>
and in the manifest:
<activity
android:name="com.fitsby.LoginActivity"
android:screenOrientation="portrait"
android:theme="#style/AppTheme" >
</activity>
Any ideas why that is happening? I do not see a problem, since AppTheme clearly inherits from one of the AppCompat Themes.
If you have different values folder in your application, for different API levels, make sure that each of those themes from the folders extend from the required Theme.AppCompat.* themes.
Related
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.
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.
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.
How to change the whole program’s Skin style?
It can use the specialized apk to implement sharing. But I do not know how to directly use the apk element in the current program.
Could you give me some advice? Thanks!
you can define style for your app.
http://developer.android.com/guide/topics/ui/themes.html
You can define a style that has one of Android theme styles as parent:
<style name="main_style" parent="android:Theme.Black.NoTitleBar">
<item name="android:windowBackground">#drawable/background</item>
<item name="android:cacheColorHint">#00000000</item>
<!-- any other customizations -->
</style>
and then, in your AndroidManifest.xml, apply it the following way
to the activity:
<activity
android:name=".Activity1"
android:theme="#style/main_style"/>
<activity
android:name=".Activity2"
android:theme="#style/main_style"/>
or to your whole application:
<application
android:theme="#style/main_style">
There's no need to define your own theme, you can also use one of stock Android themes:
<application
android:theme="#android:style/Theme.Black.NoTitleBar">
I'm using ActionBarSherlock to make my app compatible with older devices. The implementation was easy, but now i need to style the default Holo blue line that you see under the tabs to a red line.
I've been reading a few topics (topic 1, topic 2) here on SO and also the ABS doc (link), but i can't get it to work.
This is what i have so far.
In my AndroidManifest.xml i added this line to the application tag.
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" > <!-- SET THE DEFAULT THEME -->
Then in res/values/styles.xml i have:
<resources>
<style name="AppTheme" parent="android:Theme.Light" />
<style name="Theme.MyTheme" parent="Theme.Sherlock">
<item name="actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
<item name="android:actionBarStyle">#style/Widget.MyTheme.ActionBar</item>
</style>
<style name="Widget.MyTheme.ActionBar" parent="Widget.Sherlock.ActionBar">
<item name="android:background">#ff000000</item>
<item name="background">#ff000000</item>
</style>
</resources>
But when i run my app, then i still see the default blue line color.
What am i doing wrong?
EDIT
Read this if you want to fully style your ActionBarSherlock!
I found an answer here on SO which gave the following link:
http://jgilfelt.github.com/android-actionbarstylegenerator
It's an easy generator which generates all the needed files for a fully customized ABS! All you have to do is copy the generated files into the appropiate folders and you're set!
Don't forget to enable the style (you'll have to enter a style name in the generator) in your AndroidManifest. For that, see the answer below.
A few things:
You don't really need <style name="AppTheme" parent="android:Theme.Light" /> anymore unless you want to change it to inherit Theme.Sherlock and use it for your app theme. If you decide to do this you will have to use Theme.MyTheme for activities.
Either way, to fix the problem you want to change
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.Sherlock" >
to
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.MyTheme" >
OR you can apply the theme directly to your activities:
<activity
android:name="com.awesome.package.activity.SomeActivity"
android:theme="#style/Theme.MyTheme"/>
Side note, I recommend this excellent actionbar theme generator
Set in your manifest file theme as follows:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/Theme.MyTheme" >
It will preserve all Sherlock themes and will add your custom styles.