I'm using a custom background for my ActionBar. I followed the tutorial from here.
My styles.xml looks like this:
<resources>
<style name="MyTheme" parent="#android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">#style/MyActionBar</item>
</style>
<style name="MyActionBar" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/actionbar_bg</item>
</style>
</resources>
I want this ActionBar to be displayed on each activity, except the login .. so I hid the ActionBar from my login activity (tut from: stackoverflow):
public class Login extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
In my manifest I added the custom theme ... like this:
<application
android:allowBackup="true"
android:label="#string/app_name"
android:theme="#style/MyTheme"
>
When I run the application, I get the error: You need to use a Theme.AppCompat theme (or descendant) with this activity
So I searched on stackoverflow for a solution. I had to extend Activity instead of ActionBarActivity. I did this, also on my Login Activity.
But now ... I can't hide the ActionBar anymore at my Login activity because it doesnt extend ActionBarActivity anymore .. so the following code:
ActionBar actionBar = getSupportActionBar();
Won't work .. anyone have an idea how to still Hide the actionbar at the Login activity, but still with a working custom Actionbartheme?
TL;DR: I want to use a custom actionbar, but I want to hide it on my Login activity. I can let the actionbar work, but only If I let my Login activity extend from Activity, instead of ActionBarActivity - This causes the getSupportActionBar(); to stop working, So I can't hide the actionbar anymore.
Create a theme whose parent is Theme.Holo.Light.NoActionBar. Assign it to your login activity with android:theme parameter.
Just add below code in onCreate Method before setContentView() method :
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE); // add this line
setContentView(R.layout.login_layout);
Related
There are 3 different types of style in the styles.xml like the following:
<style name="Theme_A" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">#01AC50</item>
<item name="colorPrimaryDark>#FF007838</item>
<item name="colorAccent">#009688</item>"
<style>
The users are able to choose which style they want using the buttons, how can I change the whole Activity's style after clicking on the button?
How to setTheme to an activity at runtime? It doesn't work call setTheme before onCreate and setContentView has the suggestion to use
setContentView(...);
setTheme(R.style.MyTheme);
setContentView(...);
That is: it seems you need to setContentView after setTheme, as
[setTheme] should be called before any views are instantiated in the Context
Try this:-
You need to use setTheme() Function before the setContentView()
as doc say's you need to define Theme before the view instantiate.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(android.R.style.Theme_Dark);
.
.
setContentView(R.layout.main);
}
In my application i am using an activity as a dialog.Everything works fine but there is one small problem.Whenever the dialog is shown,the title bar is visible.I had done requestWindowFeature(Window.No.Title) but still the title bar is comming.
xml
<style name="CustomDialog" parent="Theme.AppCompat.Light.Dialog">
<item name="android:windowNoTitle">true</item>
</style>
you are using wrong theme
use this
android:Theme.DeviceDefault.Dialog.NoActionBar
also you can hide action bar programmatic .
for that you have to use this in your onCreate mathod
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.hide();
}
How about this ?
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); //before
dialog.setContentView(R.layout.logindialog);
add this before you show the dialog
this answer originally form here
In my android project, I wish to disable icon and the title in ActionBar.
Here is the code:
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setDisplayShowHomeEnabled(false);
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
But always on startup they appear and after a while they disappear but i don't want them at all. How can i remove them on startup?
call setDisplayShowHomeEnabled(false) and setDisplayShowTitleEnabled(false) on your ActionBar.
actionBar.setDisplayUseLogoEnabled(false); should do it.
Or
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>
Reffer this ----> click here
You can use below code for that -
<activity android:name="YourActivityname" android:theme="#android:style/Theme.NoTitleBar" />
If you want the full screen of your device you can use below code -
<activity android:name="YourActivityname" android:theme="#android:style/Theme.NoTitleBar.Fullscreen" />
And, also refer Developer's Site
Another method
Do this in your onCreate() method.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
//set content view AFTER ABOVE sequence (to avoid crash)
this.setContentView(R.layout.your_layout_name_here);
this refers to the Activity.
Maybe this answer can help you. It helped me.
<quote>
Best method is to set the display options to useLogo in your theme. E.g.
<style name="AppTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/AppTheme.ActionBar</item>
</style>
<style name="AppTheme.ActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid">
<item name="android:displayOptions">useLogo</item>
</style>
This won't actually show the logo (if set) because showHome is not included.
</quote>
try this:
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
setContentView(R.layout.activity_main);
}
NOTE: The getActionBar() method was added in Honeycomb (API: 11) and later
I already remove the title in onCreate() method.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final ActionBar actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
}
The title is not displayed. But still appears when launching the app.
And I can use
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
or put
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
into manifest file because I'm using actionBar. If I did that, the app crashes.
So, my question is, is there any way to remove the title when the app is launching because I am gonna put a splashscreen here. Thanks.
-----------
PLEASE NOTICE:
Thanks for your answers, but I clearly said that I already used actionBar.setDisplayShowTitleEnabled(false);
to hide the title bar of the activity. (as shown in the first picture)
BUT the title bar still appears in the launching screen (as shown in the second picture.)
and
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
and
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
would lead to crash launch. This happens after I used actionbar.
I had the same problem.
Personally, I solved it by replacing my Activity inheritance from
ActionBarActivity to Activity.
Hope this will help someone...
Do this in your onCreate() method.
//Remove title bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
//Remove notification bar
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this refers to the Activity.
===========
EDIT:
if you are using ActionBarSherLock
final ActionBar bar = getSupportActionBar();
bar.setDisplayShowTitleEnabled(false);
It might be crashing because you are using this.requestWindowFeature(Window.FEATURE_NO_TITLE); after setContentView();
Use this.requestWindowFeature(Window.FEATURE_NO_TITLE); in onCreate() of your Activity , before setContentView(); statement.
May be i am repeating the same which all are saying but i just need to confirm it.In manifest file have add the theme like the below which i added as sample or anyother way.
<application ....
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:largeHeap="true"> ..
</application>
Just remove all other code related to hide title bar only andonly add this one in the manifest file it works for me.I hope it will work to you too.
Nick Butcher and Katherine Kuan wrote a nice Google Plus post about a smoother app launch experience:
https://plus.google.com/+AndroidDevelopers/posts/VVpjo7KDx4H
However, if you want to be compatible with Android versions below API 14 (for example using AppCompat), the only way I could achieve this is by using a separate launch activity using a theme with no actionbar.
Set your splashscreen as your main activity and set the theme to
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
create and intent to move your splash screen to your actual main activity
Use this:
ActionBar bar = getActionBar();
bar.hide();
or
ActionBar bar = getActionBar();
bar.setDisplayShowHomeEnabled(false);
bar.setDisplayShowTitleEnabled(false);
in res/values/styles.xml
find ...
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
replacing for.
<!-- Application theme. -->
<style name="AppTheme" parent="AppBaseTheme">
<item name="windowActionBar">false</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
</style>
Save and compile...
Put below three line in onCreate Method before setContentview in your activity which want to display full screen
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Hope below lines will help you
getWindow().clearFlags(
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
You can simply add full screen theme to that activity in your manifest file:
android:theme="#android:style/Theme.Black.NoTitleBar.Fullscreen"
In your AndroidManifest.xml in application tag set your theme to full screen like in below code.
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
My android app has tab navigation using an action bar. It works well, but it bothers me that during the first boot of the app, a small default action bar briefly shows up before being replaced by the real, tab-navigation action bar. My onCreate starts like this:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
setContentView(R.layout.activity_main);
//Set up the actionbar
final ActionBar actionBar = getActionBar();
.
.
.
What do I have to do so that the real actionbar will be initialized without a small default one briefly showing before it does on startup?
Thanks
Hide during startup
getSupportActionBar().hide();
After you can show it again with ...
getSupportActionBar().show();
It should be the same with native ActionBar of Android.
you should use this line in manifest and don't use getActionBar()
<item name="android:windowActionBar">false</item>
and once it's finished in the main Activity use below or nothing
<item name="android:windowActionBar">true</item>
put this for your activity manifest definition:
<activity
android:name=".MyActivity"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>
then inside your oncreate do this to show the actual theme you want used:
setTheme(R.style.AppTheme);
if you're using action bar sherlock and you want to toggle this from a FragmentActivity, then you call
getSherlockActivity().getSupportActionBar().hide();