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">
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"/>
...
I've been having a very hard time trying to get rid of the Title Bar on the application I'm developing. I'm using Android Studio.
I've tried almost all the methods that have been listed on various places on the net..
super.onCreate()...
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // also used it without the "this"
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.setContentView(R.layout.your_layout_name_here);
in the .java file
also tried a couple of other methods in the .java file
I've tried changing the codes in the manifest file as well using
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen">
even by changing the theme under the Application tag..
I've tried changing the style tag in the styles.xml to something like
<style name="AppTheme">
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
but all of these have failed. The app has CRASHED in all of the above instances. Any help will be deeply appreciated.
try this before your setContentView(..)
Window window = getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
if (Build.VERSION.SDK_INT > 20)
window.setStatusBarColor(getResources().getColor(R.color.color_white));
or if your ok with it. #android:style/Theme.Holo.NoActionBar though i prefer not using this.
or if youre using appCompat libs
1.Go to your manifest.xml file.
2.Find the activity tag for which you want to hide your ActionBar and then add,
android:theme="#style/Theme.AppCompat.NoActionBar"
<activity android:name=".MainActivity" android:theme="#style/Theme.AppCompat.NoActionBar">
I think you are extending either actionbaractivity or appcompatactivity .Instead of them simply extend Activity and then use
requestWindowFeature(Window.FEATURE_NO_TITLE);
Initially in the manifest when i don't set any theme inside the activity tag my option menu look like this which is default..
But once i set this theme android:theme="#android:style/Theme.NoTitleBar" in the activity tag of my manifest file the option menu style changes.
Screen shots after adding android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen"
Why this happen.
Try this.
<activity
android:theme="#android:style/Theme.Holo.NoActionBar.Fullscreen" >
Look Here For Android Holo themes with backwards compatibility
Edit Try android:showAsAction="ifRoom" in menu.xml file. Look at this for More
My goal is to show a splash screen on my applications startup. Right now what it will do is briefly show the actionbar with an otherwise blank page, then jump to the splash screen. I'm trying to figure out how to not show the beginning screen and just start with the splash screen.
I'm trying to use these links for information on how to solve this.
ActionBar Lag in hiding title
In this one I'm assuming I can use the same type of method for hiding the actionbar by changing the theme, but I don't know what I would actually use as my style to do so.
How to hide action bar before activity is created, and then show it again?
and here it talks about adding a line to the manifest that would do it. Where in the manifest? Anywhere I put it did not do anything.
try this in manifest file
<activity
android:name="yourActivityName"
android:label="your label"
android:theme="#android:style/Theme.Holo.Light.NoActionBar.Fullscreen" >
</activity>
Check this link Android: hide action bar while view load
Code snippets from the link, incase the link breaks down, courtesy #kleopatra:
Setting the properties windowNoTitle to true on your theme will
hide the ActionBar. use two different themes both extending parent="Theme.AppCompat.Light" in order to prevent NPE when using getSupportActionBar
set the styles as
<style name="AppThemeNoBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">true</item>
</style>
<style name="AppThemeBar" parent="Theme.AppCompat.Light">
<item name="android:windowNoTitle">false</item>
</style>
Due to some odd behaviour on versions < 11, you need to add
if (Build.VERSION.SDK_INT < 11){
getSupportActionBar().hide(); }
inside activities that do not need the actionbar
Delete the "android:label" entries in Manifest file, from application and the first activity which is loaded. In your case, the Splash activity.
Sample...
<application
android:allowBackup="true"
android:icon="#drawable/starticon"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo">
<activity
android:name=".ActivitySplash"
android:label="#string/app_name"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
Just add this code in your Activity in the onCreate function.
val actionBar = supportActionBar?.apply{hide()}
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