I'm confused while reading some materials to set theme we use android:theme some like that, then where we can use its property?
Which property can be set in AndroidManifest.xml file for changing theme?
In your AndroidManifest.xml android:theme="#style/yourTheme" in each activity p.e.
<activity
android:name="com.example.helpingblind.Words"
android:label="#string/title_activity_words"
android:theme="#style/yourTheme1>
</activity>
<activity
android:name="com.example.helpingblind.Words"
android:label="#string/title_activity_words"
android:theme="#style/yourTheme2>
</activity>
This way you can implement a theme in each activity if you want
Related
Every time I restart Android Studio, the theme of all the activities get changed to either "Theme" or "Light", whereas I want to keep the theme as "AppTheme.NoActionBar".
I have included the line:
android:theme="#style/AppTheme.NoActionBar" in my android manifest file.
Be sure which theme is defined in you mainifest, in the part where you define your application:
<application
android:name=".ExampleApp"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme.NoActionBar">
...
This is the theme of your application, if you want a specific theme in your activity, you have to set:
android:theme ="#android:style/AppTheme.NoActionBar"/>
into your activity tags:
<activity
android:theme ="#android:style/AppTheme.NoActionBar"/>
...
Please suggest ways to remove/hide the name of activity from action bar of my app. If there is a tutorial or a guide available on how to do it, that would be great. TIA
If you want to edit it from the code then
getActionBar().setTitle("Edited Title");
or
getSupportActionBar().setTitle("Edited Title");
this might help you https://developer.android.com/training/basics/actionbar/styling.html
Try this code before setting the content view in the activity oncreate method.
requestWindowFeature(Window.FEATURE_NO_TITLE);
yes, you need to change the theme of your application.
<activity android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
Just set "android:theme" attribute to "#android:style/Theme.NoTitleBar" on your element in your AndroidManifest.xml file
<activity android:name=".MyActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
</activity>
If i have specified my Theme for the application such as so:
<application
android:name="main_application.GlobalObjects"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Do I then need to specify the Theme again for each activity defined in the manifest file like so:
<activity
android:name="main_application.MainActivity"
android:label="#string/app_name" >
android:theme="#style/AppTheme" >
</activity>
Or do i only need to do this when over riding the applications theme for a single activity?
Do I then need to specify the Theme again for each activity defined in the manifest file like so
No, Once you have defined the Theme for the application and applied it in manifest <application> tag then there is not need of specifying Theme for each Activity again.
But if you want different Themes for each activity then in this case you can define separate themes for each activity.
Do I then need to specify the Theme again for each activity defined in the manifest file like so
No. If you need a specific Theme for a particular Activity then you can set it on the Activity. Otherwise just set it on the <application>
Activity and Application Themes
If you want to use same theme all over the application then setting theme in application tag in manifest is good enough. For example, this part of your code
<application
android:name="main_application.GlobalObjects"
android:allowBackup="true"
android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
But if you want to use different theme in different activities then you have to specify the theme like your code
<activity
android:name="main_application.MainActivity"
android:label="#string/app_name"
android:theme="#style/ThemeForThisActivity" />
If you need different theme for each of your activity then YES.
If you need same theme for your application then NO.
I know how to apply a theme to a whole application, but where would I go to apply a theme to just a single activity?
You can apply a theme to any activity by including android:theme inside <activity> inside manifest file.
For example:
<activity android:theme="#android:style/Theme.Dialog">
<activity android:theme="#style/CustomTheme">
And if you want to set theme programatically then use setTheme() before calling setContentView() and super.onCreate() method inside onCreate() method.
To set it programmatically in Activity.java:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.MyTheme); // (for Custom theme)
setTheme(android.R.style.Theme_Holo); // (for Android Built In Theme)
this.setContentView(R.layout.myactivity);
To set in Application scope in Manifest.xml (all activities):
<application
android:theme="#android:style/Theme.Holo"
android:theme="#style/MyTheme">
To set in Activity scope in Manifest.xml (single activity):
<activity
android:theme="#android:style/Theme.Holo"
android:theme="#style/MyTheme">
To build a custom theme, you will have to declare theme in
themes.xml file, and set styles in styles.xml file.
Before you call setContentView(), call setTheme(android.R.style...) and just replace the ... with the theme that you want(Theme, Theme_NoTitleBar, etc.).
Or if your theme is a custom theme, then replace the entire thing, so you get setTheme(yourThemesResouceId)
I'm looking for to set the default titlebar in one layout into my app. But I'd set the Theme of the app to NoTitleBar.
How can I add by code to set/appear the titlebar?
Thx.
You can specify the theme for each activity in your AndroidManifest.xml file:
<activity android:name="Activity1" android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"/>
<activity android:name="Activity" android:label="#string/app_name"
android:theme="#android:style/SOMETHING_ELSE"/>
You can override a theme set on <application>, by defining theme on <activity>.