I am setting theme for each activity seperately in the corresponding activity.java file.
setTheme(android.R.style.Theme_Holo_Light);
Can i set the theme globally in the manifest file and then override it to change action bar background color etc.
In AndroidManifest.xml
<application
android:theme="#style/MyAppTheme">
In styles.xml
<style name="MyAppTheme" parent="#android:style/Theme.Holo.Light">
</style>
But it crashes.Why?
as per my guessing it is happening
cause your using theme which is not supporting to actionbar and your calling actionbar related code in such activity i mean your app may be crashing in that activity where you write actionbar related code but unfortunately the theme for that activity is not actionbar related theme thats why may be it comes
use actionbar related theme in that activity using
android:theme="#style/actionbar supported theme"
line in manifest against that activity
Related
Android Pie added the ability to toggle light/dark theme in the Settings -> Display -> Device Theme menu.
I want my app to apply the correct theme according to the Device Theme set in the device settings.
According to the Styles and Themes Android guide, for dark mode the app should use a theme that extends Theme.AppCompat, and for light mode the app should use a theme that extends Theme.AppCompat.Light.
So I created two themes in my app:
<style name="AppTheme.Dark" parent="Theme.AppCompat">
...
</style>
<style name="AppTheme.Light" parent="Theme.AppCompat.Light">
...
</style>
However in AndroidManifest.xml when I declare the application with the <application> tag I can only specify one theme in the android:theme attribute:
<application
android:name=".MyApplication"
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="#style/AppTheme.Light"
tools:replace="android:name">
How do I declare my application in AndroidManifest.xml to dynamically pick #style/AppTheme.Light or #style/AppTheme.Dark according to the Device Theme set in the device settings?
If you want to change theme of an already existing activity, call recreate() after setTheme().
Note: don't call recreate if you change theme in onCreate(), to avoid infinite loop.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Call setTheme before creation of any(!) View.
setTheme(android.R.style.Theme_Dark);
// ...
setContentView(R.layout.main);
}
You may want to try Theme.AppCompat.DayNight instead of defining two themes. Its implementation in this video Cost of a Pixel Color.
However, when I test this on an emulator, toggling Settings -> Display -> Device Theme menu doesn't work. I have to toggle Developer Options -> Night Mode -> Always On and dark theme is picked automatically.
Since I don't own an Android Pie device, I'm not sure if this is a bug of emulator.
I am making android app using Visual Studio with the Xamarin platform.
As i read the document the thing I found.
.
As we can see there is only three Theme we can create. So my Question is can we set NoActionBar theme to Application as we can set in Android Studio.
Any Help be Appreciated.
You can use Theme with no Action bar in your app. For ex, you can specify Application Attribute in Properties\AssemblyInfo.cs:
[assembly: Application(Icon = "#drawable/Icon" Theme = "#android:Theme.Holo.Light.NoActionBar")]
Or set it in AndroidManifaset.xml
<application android:theme="#android:style/Theme.Holo.Light.NoActionBar" />
If that does not work, create a style with no action bar, like it's mentioned in here: https://stackoverflow.com/a/14061826/85606
No actionbar with styles
<style name="NoActionBar" parent="#android:style/Theme.Holo.Light.NoActionBar">
</style>
How to hide the action bar and get full screen with Theme.AppCompat.Light on Android 2.x? I had tried following code on styles.xml:
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
It doens't work. How to solve without use java code?
That configuration works. Just make sure you are adding the correct Theme from the correct styles.xml (not from values-vXX folder styles) file to your Activity in manifest.xml file.
Also make sure your Activity does not extend ActionBarActivity, but FragmentActivity, as you do not want the ActionBar to show.
In my application, I'm using ActionBarSherlock library. Also I'm using a custom title bar.
Here goes my onCreate:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main_tab);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title);
And in my styles.mxl
<style name="MyTheme" parent="Theme.Sherlock">
<item name="android:background">#ff888888</item>
<item name="android:windowNoTitle">false</item>
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleBackgroundStyle">#style/windowTitleBackgroundStyle</item>
</style>
<style name="windowTitleBackgroundStyle">
<item name="android:background">#00688B</item>
</style>
In Manifest file i am using MyTheme for the activity.
android:theme="#style/MyTheme"
This code properly works with lower android version (I have tested with GB2.3.5). But when i tested with ICS, its crashing with the Below error:
"You cannot combine custom title with other title features"
I went thoroughly in StackOVerflow discussions, but unable to resolve the issue.
solutions tried:
1) false
2) there is no values-v11 folder
I received the same exception.
Here is what I found: In newer versions of Android, the framework will use the Window.FEATURE_ACTION_BAR feature whenever the Holo theme is selected. The framework throws the exception whenever an app calls setFeatureInt(Window.FEATURE_CUSTOM_TITLE) and FEATURE_ACTION_BAR has already been set.
In my case, the styles.xml file in the values-v11 folder was redefining my theme to inherit from android:Theme.Holo. When I attempted to run my app on a Android 3.0 or above - it crashed because Holo uses the ActionBar by default. The fix was simple. Turn the ActionBar off when using Holo. Here is the revised values-v11\styles.xml changes:
<style name="AppBaseTheme" parent="android:Theme.Holo.NoActionBar">
<!-- API 11 theme customizations can go here. -->
</style>
I had the same problem and solved it:
THE ROOT CAUSE:
In the Manifest, I copy pasted this tag by mistake from my splash screen into my activity: #android:style/Theme.NoTitleBar
The fatal exception occured when I also requested a FEATURE_CUSTOM_TITLE on my activity, causing the conflict.
SOLUTION:
To fix it, I checked these 3 things:
1)OnCreate method:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.activity_login);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_titlebar);
}
2)INSIDE your manifest.xml:
Make sure a line such as these ONLY appears in a splash screen if you have one:
android:theme="#android:style/Theme.NoTitleBar
REMOVE that line from any other activity if you want a custom Bar.
In the application tag , my only theme tag is this one:
android:theme="#style/AppTheme"
In the activity tag, I have no theme tag.
3) Go to your activity's XML layout, and view it in GRAPHIC LAYOUT mode.
Maye sure your that the Theme says AppTheme (its the the you put on the manifest)
Mine said "No Title", so this was causing the problem.
Why is there a difference between theme defined in AndroidManifest.xml and theme taken from styles.xml?
1) AndroidManifest.xml:
<application ... android:theme="#android:style/Theme.Black">
2) AndroidManifest.xml
<application ... android:theme="#style/AppTheme">
styles.xml
<resources>
<style name="AppTheme" parent="#android:style/Theme.Black" />
</resources>
1st setting gives black theme and no action bar. 2nd has dark action bar and light menu.
EDIT : options 1) and 2) - notice Menu and ActionBar
EDIT 2:
Why doesn't the 2nd option actually use the AppTheme (Theme.Black) ? (tested on SGS3)
You probably have another styles.xml file, perhaps under a directory like "values-v11", that is defining the #style/AppTheme differently than #android:style/Theme.Black and taking precedence over the file you're viewing/modifying.
#android:style/Theme.Black implements the exact theme implemented by Android (or device manufacturer). However, #style/AppTheme allows you to perform custom modification in your theme which actually extends the original Theme.Black from android, and in order to perform custom modifications, you use style resources.
In simple words, its just like using Activity class or YourOwnActivity class which extends Activity with extra features inside.
Styles.xml enables you to create your own themes. In AndroidManifest, you set the theme you want for an app or activity. You may want to use a system theme or your own. You can also extend other themes as you're doing setting "parent" attribute. For further information, check this out:
http://developer.android.com/guide/topics/ui/themes.html
You should try to put:
<resources>
<style name="AppTheme" parent="#android:style/Theme.Black" />
</resources>
in a xml file called res/themes.xml