I have added a Toolbar to my AboutApplication activity. I have also added a navigation button to this toolbar -
when this button is clicked, the application should navigate to the previous activity (LoginActivity).
I tried calling the finish inside method onBackPressed() and this did not work. I tried creating an OnClickEventListener() for the toolbar's setNavigationOnClickListener() - this did not work either.
Here is the code for my AboutApplication activity:
public class AboutApplicationActivity extends AppCompatActivity {
private NavigationOnClickListener myListener;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_application);
myListener = new NavigationOnClickListener(this);
myListener.setNextActivity(new LoginActivity());
TextView toolbarTitle = (TextView) findViewById(R.id.aboutApplication);
Toolbar toolbar = (Toolbar) findViewById(R.id.aboutApplicationToolbar);
toolbar.setNavigationIcon(R.drawable.back);
toolbar.setNavigationOnClickListener(myListener);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowTitleEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
Do not confuse what you want with Navigation Design, you are requirement matches a lot like Up navigation provided by android, why do you want to make it around when this feature is already provided to you.
if your AboutApplication Activity comes from LoginActivity then you should apply Up Navigation provided my Android which know the best, let it handle it.
Things that you need to take care of while you are providing up navigation is that you properly define the child-parent structure in the AndroidManifest.xml file in your android project
<!-- Assuming this activity would be a parent -->
<activity
android:name="com.example.myfirstapp.LoginActivity" ...>
...
</activity>
<!-- this would be your child activity in your case `AboutApplicationActivity` -->
<activity
android:name=".AboutApplicationActivity"
>
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstapp.LoginActivity" />
</activity>
now in your child activity things you need to make sure is this,
getActionBar().setDisplayHomeAsUpEnabled(true); // without support library
getSupportActionBar().setDisplayHomeAsUpEnabled(true); // support library
and offcours by now you know where does this goes
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
if you have hard time importing NavUtils.java, than write its fully qualified name android.support.v4.app.NavUtils
for more details use android documentation here,
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Anyone know why my action bar/ my android title bar is missing when I extends Activity? All this while it is working fine and the action bar/ title activity is being shown on the activity whenever I used extend activity. I have been using extend activity for a very long time, but today when I click on create new Project to create a new android activity and extends activity, the action bar/ android title went missing. I have been searching for quite some time now and still unable to find the reason that causes this. How to fix this?
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Thanks
As Shvet already pointed out the fastest fix would be to use AppcompatActivity as base class, since this class adds the new Toolbar by default.
The reason why you don't see the ActionBar is that it is hidden by default in the compat style. So you would need to change the style to something different in your manifest. But I would suggest you to use the compat library. That makes the compatibility much more easy.
ActionBar is deprecated ever since Toolbar was introduced. Toolbar can be seen as a 'superset' of any action bar. So the 'old' ActionBar is now an example of a Toolbar. If you want similar functionality, but without deprecation warnings do the following:
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
toolbar.setTitle(R.string.app_name);
setSupportActionBar(toolbar);
}
You need to define the Toolbar in your 'layout.xml' file like so:
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toolbar"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="#style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="#style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
With this new functionality you can create your own custom ActionBar and let Android do the heavy lifting. Just create your own custom view that extends from Toolbar
Simple change your extends Activity to ActionBarActivity and use ActionBar class you will get action bar from your activity.
My app uses the android.support.v7.app.ActionBar so that I can use the Action Bar on my Android 2.3.4 phone and my tablet using Android 4.4.2. I've got my minimum and target SDK's set at 10 and 18. When I click the back button on the Action Bar which calls setDisplayHomeAsUpEnabled(true) it works correctly on the 2.3.4 phone and goes back to the Home Activity called Main_Interface. But when I click the back button on the Action Bar on the tablet, it closes the app as if I clicked the back button on the tablet. Nothing comes up in LogCat, so it's acting as though it's supposed to close the app when the Action Bar setDisplayHomeAsUpEnabled() button is clicked. Here's what the Activity looks like in the Manifest:
<activity
android:name=".UILNPPager"
android:configChanges="orientation|screenSize"
android:label="UILNPPager"
android:parentActivityName="com.myapp.ktg.Main_Interface"
android:theme="#style/Theme.Blu_uilpager" >
<intent-filter>
<action android:name="com.myapp.ktg.UILNPPAGER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.myapp.ktg.Main_Interface" />
</activity>
Here's the Activity stripped of everything but the ActionBar calls:
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarActivity;
public class UILNPPager extends ActionBarActivity {
private static final String STATE_POSITION = "STATE_POSITION";
DisplayImageOptions options;
ViewPager pager;
String[] imTitlesStr;
String[] imMediumStr;
String[] imPriceStr;
String[] imageUrls;
int pagerPosition;
PhotoViewAttacher mAttacher;
ActionBar mActionbar;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.actionbar_uilpager);
//--- ViewPager stuff
....
//--- END ViewPager stuff
/** Getting a reference to action bar of this activity */
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main_actions, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
I tried taking the call android:parentActivityName="com.myapp.ktg.Main_Interface" out of the manifest, but that has no effect. It still works correctly on the 2.3.4 phone and not on the 4.4.2 tablet.
Any idea why it doesn't work right on the tablet?
Please use a AppCompat theme or a theme that inherits one of them. For example:
#style/ThemeAppCompat
#style/ThemeAppCompat.Light
#style/ThemeAppCompat.Light.DarkActionBar
I noticed that you are using your own styled theme, you can inherit the theme from one of the AppCompat theme as follow.
<style name="Theme.Blu_uilpager"
parent="#style/ThemeAppCompat.Light">
....
</style>
Quoted from a official Android tutorial, https://developer.android.com/training/basics/actionbar/styling.html
Note: If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher). In doing so, each style property that you declare must be declared twice: once using the platform's style properties (the android: properties) and once using the style properties included in the Support Library (the appcompat.R.attr properties—the context for these properties is actually your app). See the examples below for details.
In my app I'm using my own transitions to move from Activity A to Activity B. I've discovered that the call overridePendingTransition(); in the onPause(); call in Activity A breaks the getSupportActionBar().setDisplayHomeAsUpEnabled(true); call in Activity B, which has the ActionBar. So on Activity A, I removed the onPause() method and called overridePendingTransition(); in the Intent that calls Activity B, like this:
Intent miI = new Intent();
miI.setClass(Splash.this, Main_Interface.class);
startActivity(miI);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
Then in Activity B I removed the onPause(); method and added overridePendingTransition(R.anim.fadein, R.anim.fadeout); to the onCreate(); method like so:
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.fadein, R.anim.fadeout);
setContentView(R.layout.mainpage);
Then I put the overridePendingTransition(); call in all other Activities' onCreate(); methods just like in Activity B. Doing this makes the transition work correctly. And to make the ActionBar go back to the Main_Interface Activity correctly on my 4.4.2 tablet, I just call getSupportActionBar().setDisplayHomeAsUpEnabled(true);. And everything is working correctly!
I am using the AlarmManager to pass a PendingIntent to my BroadcastReceiver after, say, 5 minutes. Now, I want to show a DialogFragment to the user, on top of whatever app the user might be using when the alarm goes off. For example, if the user is using Chrome when the alarm goes off, my DialogFragment should popup ABOVE the user's Chrome window.
What I am ending up with instead, is the DialogFragment being shown with a blank activity of my app as the background (as in the following pic)
http://i.stack.imgur.com/Vz9IZ.png
This is the code I am using in my BroadcastReceiver, to launch an FragmentActivity first :
public class AlarmReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent)
{
Intent hardReminderIntent = new Intent(context, AlarmHardActivity.class);
hardReminderIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(hardReminderIntent);
}
}
Next, from this activity, I am popping up the DialogFragment :
public class AlarmHardActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FragmentManager fm = getSupportFragmentManager();
AlarmHardDialog editNameDialog = new AlarmHardDialog();
editNameDialog.show(fm, "fragment_dialog");
//setContentView(R.layout.activity_alarm_hard);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
//getMenuInflater().inflate(R.menu.activity_alarm_hard, menu);
return true;
}
}
My questions :
I could not find a way to call getSupportFragmentManager directly from the onReceive in my BroadcastReceiver, and thus assumed that the only way to obtain a dialog, would be to first call a 'dummy' activity, that creates the dialog. Is there a better way to do this?
Irrespective of whether or not my approach was correct, I expected that since there is no call to setContentView(..) in AlarmHardActivity, there would be no UI rendered for it. Is my understanding wrong? I also tried calling setContentView(..) and then marking the layout to have Theme.NoDisplay and android:alpha="0", but to no avail.
Any help will be much appreciated. Thanks!
Instead of showing dialog on the activity, better alternative will be making activity look like dialog by using dialog theme and setting margin of all sides to desirable dp, so that activity get shrieked to dialog box size.
For few examples look at these posts:
Android Activity as a dialog
Android: how to create a transparent dialog-themed activity
How to set a dialog themed activity width to screen width?
To your questions:
Fragments can be attached only to Activity (ActivityFragment). So yes, you need dummy Activity for this.
Use the invisible theme #android:style/Theme.Translucent.NoTitleBar, calling setContentView isn't necessary. But this theme isn't Holo compatible (in dialog you would have old Android look). I solved this with custom theme (I use this from ICS, but it should work from HONEYCOMB):
<style name="InvisibleTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">#null</item>
<item name="android:windowIsTranslucent">true</item>
<!-- Note that we use the base animation style here (that is no animations) because we really have no idea how this kind of activity will be used. -->
<item name="android:windowAnimationStyle">#android:style/Animation</item>
</style>
It is impossible to show this dialog without Activity. You can try to run your app like you have on your screenshoot, but with transparent background and hidden ActionBar. But i have never tried to do that so I'm not sure if it will work.
I need to implement splash screen in my honeycomb app.
I use this code in activity's onCreate to show splash:
setContentView(R.layout.splash);
getActionBar().hide();
and this code to show main UI after sometime:
setContentView(R.layout.main);
getActionBar().show();
But before onCreate is called and splash appears, there is small amount of time when action bar shown.
How can I make action bar invisible?
I tried to apply theme to activity without action bar:
<item name="android:windowActionBar">false</item>
but in that case getActionBar() always returns null and I found no way to show it again.
Setting android:windowActionBar="false" truly disables the ActionBar but then, as you say, getActionBar(); returns null.
This is solved by:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.splash); // be sure you call this AFTER requestFeature
This creates the ActionBar and immediately hides it before it had the chance to be displayed.
But now there is another problem. After putting windowActionBar="false" in the theme, the Activity draws its normal Window Title instead of an ActionBar.
If we try to avoid this by using some of the *.NoTitleBar stock themes or we try to put <item name="android:windowNoTitle">true</item> in our own theme, it won't work.
The reason is that the ActionBar depends on the Window Title to display itself - that is the ActionBar is a transformed Window Title.
So the trick which can help us out is to add one more thing to our Activity theme xml:
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleSize">0dp</item>
This will make the Window Title with zero height, thus practically invisible .
In your case, after you are done with displaying the splash screen you can simply call
setContentView(R.layout.main);
getActionBar().show();
and you are done. The Activity will start with no ActionBar flickering, nor Window Title showing.
ADDON:
If you show and hide the ActionBar multiple times maybe you have noticed that the first showing is not animated. From then on showing and hiding are animated. If you want to have animation on the first showing too you can use this:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_ACTION_BAR);
// delaying the hiding of the ActionBar
Handler h = new Handler();
h.post(new Runnable() {
#Override
public void run() {
getActionBar().hide();
}
});
The same thing can be achieved with:
protected void onPostResume() {
super.onPostResume();
getActionBar().hide();
but it may need some extra logic to check if this is the first showing of the Activity.
The idea is to delay a little the hiding of the ActionBar. In a way we let the ActionBar be shown, but then hide it immediately. Thus we go beyond the first non-animated showing and next showing will be considered second, thus it will be animated.
As you may have guessed there is a chance that the ActionBar could be seen before it has been hidden by the delayed operation. This is actually the case. Most of the time nothing is seen but yet, once in a while, you can see the ActionBar flicker for a split second.
In any case this is not a pretty solution, so I welcome any suggestions.
Addition for v7 support actionbar user, the code will be:
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getSupportActionBar().hide();
Using this simple code in your .class file to hide action bar
getSupportActionBar().hide();
If you are using ActionBarSherlock, then use Theme.Sherlock.NoActionBar Theme in your Activity
<activity
android:name=".SplashScreenActivity"
android:theme="#style/Theme.Sherlock.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Create two styles:
<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>
Set AppThemeNoBar as application theme and AppThemeBar to the activity where you want to show the ActionBar.
Using two styles you wont see the Action bar while views are loading.
Check this link Android: hide action bar while view load
Hi I have a simple solution by using 2 themes
Splash screen theme (add it to the manifest):
<style name="SplashTheme" parent="#android:style/Theme.Holo.NoActionBar">
<item name="android:windowBackground">#color/red</item>
</style>
normal theme (add it in your activity by setTheme(R.style.Theme)):
<style name="Theme" parent="#style/Theme.Holo"> <item name="android:windowBackground">#color/blue</item>
</style>
To support SDK 10:
#Override
public void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme);
super.onCreate(savedInstanceState);
...........
...........
}
I was also trying to hide Action Bar on Android 2.2, but none of these solution worked. Everything ends with a crash. I checked the DDMS LOg, It was telling me to use 'Theme.AppCompat'.At last I Solved the problem by changing the android:theme="#android:style/Theme.Holo.Light.NoActionBar"Line
into android:theme="#style/Theme.AppCompat.NoActionBar"and it worked, but the the Interface was dark.
then i tried android:theme="#style/Theme.AppCompat.Light.NoActionBar" and finally got what i wanted.
After that when I Searched about 'AppCompat' on Developer Site I got This.
So I think the Solution for Android 2.2 is
<activity
android:name=".MainActivity"
android:theme="#style/Theme.AppCompat.Light.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
And Sorry for my bad English Like Always.
Best result to me was to create an activity with ThemeNoTitleBar and without content as launcher. Then this activity call directly to the other.
Of course if you want you can add content to the Splash Activity but in my case I just wanted to show application directly.
Manifest:
<activity
android:name="com.package.SplashActivity"
android:theme="#android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Activity:
public class SplashActivity extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//start StartActivity
Intent intent = new Intent(this, StartActivity.class);
startActivity(intent);
finish();
}
}
If you use one Activity included a splash screen, then you can do this if you use SherlockActionBar
getSupportActionBar().hide();
After the splash screen you can show it again with ...
getSupportActionBar().show();
It should be the same with native ActionBar of Android.
#Clerics solution works. But this appears to also be an issue with some of googles native apps: googles, play store, talk. Also other big apps like skype.
EDIT: Bellow solution have given me problem for actionbarsherlock on api < 4.0, the reason being setTheme doesn't work pre ice cream sandwich
Add following in your manifest within you application or activity tags:
android:theme="#style/Theme.NoActionBar"
And then in your main activity:
// Set theme
setTheme(R.style.YOUR_THEME);
getSupportActionBar().setTitle(R.string.title);
// Start regular onCreate()
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
best and simple
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
2015, using support v7 library with AppCompat theme, set this theme for your Activity.
<style name="AppTheme.AppStyled" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimaryDark">#color/md_indigo_100</item>
<item name="colorPrimary">#color/md_indigo_500</item>
<item name="colorAccent">#color/md_red_500</item>
<item name="android:textColorPrimary">#color/md_white_1000</item>
<item name="android:textColor">#color/md_purple_500</item>
<item name="android:textStyle">bold</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
For Splashscreen you should use this line in manifest and don't use getActionBar()
<item name="android:windowActionBar">false</item>
and once when Splash Activity is finished in the main Activity use below or nothing
<item name="android:windowActionBar">true</item>
Try this, it works for me:
Below gets rid of activity's title bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
Below eliminates the notification bar to make the activity go full-screen
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
(Full Example Below)
Take note: These methods were called before we set the content view of our activity
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Sets Application to full screen by removing action bar
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
// without this check, we would create a new fragment at each orientation change!
if (null == savedInstanceState)
createFragment();
}
this may be handy
add this to your manifest
android:theme="#android:style/Theme.Light.NoTitleBar"
cheers
The best way I find after reading all the available options is set main theme without ActionBar and then set up MyTheme in code in parent of all Activity.
Manifest:
<application
...
android:theme="#android:style/Theme.Holo.Light.NoActionBar"
...>
BaseActivity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.GreenHoloTheme);
}
This way helps me to avoid ActionBar when application start!
The solutions already posted came with the sideffect, that the first .show() call did not animate the ActionBar for me.
I got another nice solution, which fixed that:
Create a transparent drawable - something like that:
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid
android:color="#00000000" />
</shape>
Set the actual actionbar background to a invisible custom view which you set on the actionbar:
getSupportActionBar().setCustomView(R.layout.actionbar_custom_layout);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
Set the transparent background for the actionbar in onCreate:
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.background_transparent));
Imortant: Don't hide the actionbar immediately in onCreate, but with a little delay later - e.g. when the layout is finished with creation:
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
#Override
public void onGlobalLayout() {
getSupportActionBar().hide();
}
});
Before your first .show() call set the custom view visible:
_actionbarRoot.setVisibility(View.VISIBLE);
getSupportActionBar().show();
In case you have null because you are using the support library, instead of getActionBar() you need to call getSupportActionBar().
Just add this to your MainActivity in the onCreate function.
val actionBar = supportActionBar?.apply { hide() }
Put your splash screen in a separate activity and use startActivityForResult from your main activity's onCreate method to display it. This works because, according to the docs:
As a special case, if you call startActivityForResult() with a requestCode >= 0 during the initial onCreate(Bundle savedInstanceState)/onResume() of your activity, then your window will not be displayed until a result is returned back from the started activity. This is to avoid visible flickering when redirecting to another activity.
You should probably do this only if the argument to onCreate is null (indicating a fresh launch of your activity, as opposed to a restart due to a configuration change).
I had still error with null pointer and finally it helped when I called first getWindow().requestFeature() and then super.onCreate()
public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
super.onCreate(savedInstanceState);
getActionBar().show();
Just add this in your styles.xml
<item name="android:windowNoTitle">true</item>
Actually, you could simply set splash Activity with NoActionBar
and set your main activity with action bar.
The best way to do this is two make the first activity as blank activity and the content you want to put and then after some time fire another activity.
By following this way you can make the first activity as your splash screen without action bar or anything.
Heres my first activity
package com.superoriginal.rootashadnasim.syllabus;
import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class first_screen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_screen);
final Handler h=new Handler();
h.postDelayed(new Runnable() {
#Override
public void run() {
Intent intent=new Intent(getApplicationContext(),DrawerChooseBranchMainActivity.class);
startActivity(intent);
}
},2000);
}
}
After that you can put any of your activity as first activity
If you want no action bar in any screen then just add this in your styles
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
Android studio provide in build template for full screen, if you use Android studio you can follow below step to implement full screen activity.
Done. Android studio did your job, now you can check code for full screen.
this is the best way I used
Go to java file, after onCreate:
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Take instance of Action Bar
// using getSupportActionBar and
// if it is not Null
// then call hide function
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
}
I realise that posting links are not the best way to do things, but I highly recommend you read the following documentation from Google themselves. This is the official android doc on how to control your system ui (things like actionbar, nav bar etc). Unfortunately the info is too much to post directly, but after reading this you will understand exactly how to show and hide features no matter what version you are developing for, its so simple!
Incase the link ever changes, it can be found under the official android documentation under training -> getting started -> Best practices for user interface -> managing the system ui
https://developer.android.com/training/system-ui/index.html
you can use this :
getSupportActionBar().hide(); if it doesn't work try this one :
getActionBar().hide();
if above doesn't work try like this :
in your directory = res/values/style.xml , open style.xml -> there is attribute parent change to parent="Theme.AppCompat.Light.DarkActionBar"
if all of it doesn't work too. i don't know anymore. but for me it works.