Activity with action bar but without title? - android

How to achieve this? It seems very simple, but actually it's not easy to do it in acceptable way. I tried this:
1) in AndroidManifest I set activity theme to Theme.NoTitleBar. However, in my Activity then getActionBar() method returns null => UNUSABLE
2) I hide title programatically in my activity by calling:
actionbar.setDisplayShowTitleEnabled(false);
actionbar.setDisplayShowHomeEnabled(false);
and it helped, but there's a little delay, so I can see title bar maybe quarter of second after activity launch, then it disappears. It looks really lame.
Are there other options?

Apply a custom theme to your Activity, something like:
<style name="TestTheme" parent="android:Theme.Holo.Light">
<item name="android:actionBarStyle">#style/TestActionBar</item>
</style>
<style name="TestActionBar" parent="android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#drawable/actionbar_background</item>
<item name="android:displayOptions"></item>
</style>
This will show the action bar with the logo, but no title.

Have u try bellow code :-
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
getActionBar().hide();
setContentView(R.layout.ur activityxml);
or also try below one
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activityxml);

Related

How to hide the action bar and get full screen with Theme.AppCompat.Light

How to hide the action bar and get full screen with Theme.AppCompat.Light on Android 2.x? I had tried following code on styles.xml:
<item name="android:windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
It doens't work. How to solve without use java code?
That configuration works. Just make sure you are adding the correct Theme from the correct styles.xml (not from values-vXX folder styles) file to your Activity in manifest.xml file.
Also make sure your Activity does not extend ActionBarActivity, but FragmentActivity, as you do not want the ActionBar to show.

android and emulator remove actionBar

hello i have to remove actionBar into an activity, this is my style:
<style name="AppTemaGiornoFullScreen" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowActionBar">false</item>
<item name="android:windowNoTitle">true</item>
</style>
this work very well into android 4x, but into an 2x emulator actionBar is always visible.. why?
You can hide it programatically from the Activity itself using this line of code in your
OnCreate method after setContentView line
getActionBar().hide();
If you are using tabs activity, use this:
getParent().getActionBar().hide();
This is a similar question .. Link
If you are asking about hiding the TitleBar programatically..Add the following lines on your onCreate before setContentView line
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
This is a similar question .. Link

How to add menu button on the navigation bar

I have a simple app which only needs a menu button with some options, and it should work in all devices.
Anyway, my app works fine in all cases, except for that I couldn't place menu button on the navigation bar.
Here is my code:
styles.xml in value folder
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">true</item>
</style>
styles.xml in value-v11 & value-v14 folders
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:windowNoTitle">false</item>
<item name="android:windowActionBar">true</item>
<item name="android:actionBarStyle">#android:style/Widget.Holo.ActionBar</item>
</style>
This code appears in all onCreate events of my activities
if(Build.VERSION.SDK_INT <= 10 || (Build.VERSION.SDK_INT >= 14 &&
ViewConfiguration.get(this).hasPermanentMenuKey()))
{
// menu key is present
ActionBar actionBar = getActionBar();
if(actionBar!=null)
actionBar.hide();
}
else
{
//No menu key
ActionBar actionBar = getActionBar();
if(actionBar!=null)
actionBar.show();
}
This code works fine, but in case I there isn't any action bar, I want to put the menu button in the navigation bar.
I've done so much googling for that, but I couldn't find any working solution for this.
Thanks in Advance.
Since nobody had answered my question, I had to answer it my self.
First, it seems it is not recommended to activate the menu button in the navigation bar! (By Google)
Anyway, if you are interested in activating it, all you have to do is:
1. Make a simple menu like before
2. Not to use an action bar
3. Set targetSdkVersion to 13 or below
And, it is highly recommended to read this article Say Goodbye To The Menu Button

Custom Title bar delay

My app uses a custom titlebar created as a layout and is implemented using this format:
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.my_layout);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.my_custom_title);
super.onCreate(savedInstanceState);
Now it did not work using the regular theme android:Theme.Light, neither did android:Theme.Light.NoTitleBar, they both resulted in a fatal exception when setContentView was called. So I created a custom style which looks like this:
<style name="MyWindowTitleBackground">
<item name="android:background">#000000</item>
</style>
<style name="CustomTheme" parent="android:Theme.Light">
<item name="android:windowTitleBackgroundStyle">#style/MyWindowTitleBackground</item>
<item name="android:windowActionBar">false</item>
<item name ="android:windowTitleSize">35dip</item>
</style>
However, every time the app is started there is a small delay in between the start and display of the actual layout with the custom titlebar, in this delay the default titlebar is shown with the appname in it. After about a second, when the Oncreate finishes, the custom title is loaded and shown.
Is there any way to fix this? What am I doing wrong?
Try putting
super.onCreate(savedInstanceState);
before the other lines and see if that works.
and putting
setContentView(R.layout.my_layout);
last. I seemed to remember my app crashing because I had it in the wrong order.

Custom title bar still shows original on startup

I'm using a custom title bar in my app and it all works fine except that when the app starts up, the original (standard) android title bar is shown for a brief time before it is replaced by my custom title bar.
This is not a problem when the app is already loaded in memory because the 'delay' is not apparent but if the app is not already in memory, it is very obvious.
There's nothing special about the code :
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
I thought about changing the style to have no window title and just include my custom title in the top of the layout but that doesn't seem right.
Thanks for any pointers.
Thomas Devaux has posted a smart solution. It worked in my app
Change the windowTitleBackgroundStyle to use color “#android:color/transparent”.
Also create a style for the text “android:windowTitleStyle” and set its “android:textColor” >to transparent as well.
For completeness to Lluis' answer, here's the full code you need to hide the default-title before the custom-title is initiated:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleStyle">
<item name="android:textColor">#android:color/transparent</item>
</style>
<style name="CustomTheme" parent="#android:style/Theme.Holo">
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleBackgroundStyle">#android:color/transparent</item>
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleStyle">#style/CustomWindowTitleStyle</item>
</style>
</resources>
add a splash screen activity before the main activity loads, should have enough time for the next one to load properly
Are you able to use an app theme to set a custom title globally for your app? See here for a pretty good example. I had a similar problem and i seem to remember going this route fixed it.

Categories

Resources