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)
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"/>
...
Can someone explain what is happening here. I load a blank Activity and two xml files are created in Android Studio; the content_main.xml, which contains all of my widgets, and activity_main.xml, which includes my contents file and looks like this:
I don't want to use this Toolbar so I delete it. Now the activity_main.xml file looks like this:
I still want to have an actionBar however. My manifest file, clearly references a theme in my styles folder:
And here is is the styles.xml file, which sets a theme for the Action Bar:
How come, when I start the emulator, my action bar is missing? My main_activity extends AppCompatActivity. Any idea why this is happening?
you are activity is overriding the Application's theme and using the NoActionBar theme. Get rid of android:theme from the <activity tag
Change from
<activity
android:theme="#style/AppTheme.NoActionBar"
android:name=".MainActivity"
android:label="#string/app_name">
to
<activity
android:name=".MainActivity"
android:label="#string/app_name">
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
I am using following code to replace title bar.
final boolean customTitleSupported = requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
And it's working fine once UI loaded. Problem is however when I start the app, the ugly gray bar appears for 1-2 seconds until UI loaded. Is there any way to specify not showing the default title bar at all?
If you want the titlebar to be gone in every activity within your app, then add
<application android:name=".YourAppNameHere"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#android:style/Theme.NoTitleBar">
to your manifest. Not 100% sure though that this will prevent the titlebar from showing up momentarily, but it should work.
In the Manifest file, add this line inside the application tag
android:theme="#android:style/Theme.NoTitleBar"
It will hide the bar from all the activities. If you want to hide it from a specific activity, add the same line to that activity's tag.
Good Luck !
You should add a line to your AndroidManifest which states that you use a theme (standard android or extended)
<application android:name=".YourAppNameHere"
android:label="#string/app_name"
android:icon="#drawable/icon"
android:theme="#style/MyTheme">
and then you can have a themes.xml in your res/values/ folder where you extend the: Theme.NoTitleBar and add custom rules to them (for example like windowBackground)
<resources>
<style name="MyTheme" parent="android:Theme.NoTitleBar">
<item name="android:windowBackground">#drawable/my_background</item>
</style>
<resources>
Have fun
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>.