getActionBar returns null - how to have NoTitleBar - android

So I have this under my Activity's onCreateView()
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
And my manifest looks like this
<activity
android:name="com.example.nfcproducttracing.ProductTracer"
android:label="#string/app_name"
android:theme="#android:style/Theme.Holo.Light"
android:launchMode="singleTask">
What I have achieved is have my application with Tabs, but no TitleBar. However, during application launch I can briefly see the TitleBar before it disappears, and I do not want that.
What am I supposed to do? When I set my activity theme to anything related to NoTitle, getActionBar returns null and the app crashes.

If I understand correctly your questions, you can use the requestWindowFeature(Window.FEATURE_NO_TITLE) from your activity.
Flag for the "no title" feature, turning off the title at the top of the screen.

Not really sure but have you tried this:
getActionBar().setTitle("");
It will set a blank title for your ActionBar.

You can try using getSupportActionBar() instead.
this is from android.support.v4.app.actionbar, not from android.app.actionbar!

Related

ActionBar Default Logo Has Wide Space

I'm working with actionBar in android and the default logo is not showing. So I have added this code to show the Logo in my onCreate method in MainActivity.
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setLogo(R.drawable.ic_launcher);
actionBar.setDisplayUseLogoEnabled(true);
Why is the logo has a wide space causing the title to not be seen?
Please help. Thanks.
This is very simple to accomplish
If you want to change it in code call
setTitle("My new title");
getActionBar().setIcon(R.drawable.my_icon);
And set the values to whatever you please.
In Manifest XML:
<activity android:name=".MyActivity"
android:icon="#drawable/my_icon"
android:label="My new title" />
To enable the back button in your app use
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);

how to remove this title from my android application

this is my app :
http://ge.tt/api/1/files/1GS1TFA2/0/blob?download
as you see in this screenshot, i need to remove this title from all tabs :
http://drp.io:8080/files/42e423e6e71e326156ee22445d90a482.png
there are other titles on the other tabs on app :
http://drp.io:8080/files/93e6c9bff3a0d0754a02869912720b51.png
i can attach any file from the app source code.
If you are coding in native Java, I think its in res/layout/yourfile.xml
You should find the string you want to change. If it's not, check res/values/strings.xml file
If you want to remove it programmatically add this before setContentView:
requestWindowFeature(Window.FEATURE_NO_TITLE);
If you want to remove it from manifest, change the theme in this into your manifest file:
android:theme="#android:style/Theme.NoTitleBar"
You could try:
ActionBar actionBar = getActionBar();
actionBar.hide();

ActionBar border won't go away when in overlay

The problem is the following one : on one of my activities, I needed a custom layout for my action bar, and the only way to do it like needed was to have a transparent ActionBar over my screen. In order to do that, I marked the ActionBar as overlay, and specified the action bar background as transparent. This works when using Android >= 15, but in 14 and below, the ActionBar keeps its bottom border. I tried anything to remove it, with no avail.
Here is a picture to see it more clearly :
On API 14 :
On API 16:
The design is the following : the Action Bar is supposed to be transparent and in overlay mode, and behind it there is a background + the logo
<ImageView
android:id="#+id/action_bar_background"
android:layout_width="match_parent"
android:layout_height="#dimen/action_bar_accueil_total_height"
android:layout_alignParentTop="true"
android:contentDescription="#string/action_bar"
android:scaleType="fitXY"
android:src="#drawable/actionbar_logo_extended" />
<ImageView
android:id="#+id/home_gallica_logo"
android:layout_width="#dimen/largeur_logo_carrousel"
android:layout_height="#dimen/action_bar_accueil_total_height"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:contentDescription="#string/action_bar"
android:src="#drawable/logo_fullcolor" />
Some precisions : I use ABS, but this does not seem to be the source of the problem, as switching to the v7 support library did exactly the same thing.
Do anyone has an idea how to remove this bottom border ?
Following the advice and the test by Luksprog in the comment, I used Theme.Sherlock (instead of Theme.Sherlock.Light) in my action bar for this page, and copied from my old theme the settings I needed. This seems to have resolved the problem, but I'm not completely sure of the source. The only advice I can give to people who are going to see this will be to use Theme.Sherlock.
I've tried to make a simple activity to showcase the behavior but I didn't manage to do it. I used an Activity with the theme Theme.Sherlock:
android:theme="#style/Theme.Sherlock
and to make the overlay(in the onCreate() method):
requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); // Window from com.actionbarsherlock.view
//...
setContentView(content);
ActionBar ab = getSupportActionBar();
ab.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
You can hide the action bar at by calling hide() method:
ActionBar actionBar = getSupportActionBar();
actionBar.hide();
Or you can set this in your manifest if you want to hide it permanently:
<activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
>

Removing left arrow from the actionbar in android?

I want to remove the left arrow from the action bar and only icon and title needed.
My code:
getSupportActionBar().setIcon(R.drawable.logo);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.dashboardtitle);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
But this doesn't remove the left arrow . Any help!!
According to specification android specification:
To enable the icon for up navigation (which displays the "up" indicator next to the icon), call setDisplayHomeAsUpEnabled(true) on your ActionBar:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
...
}
So you should set actionBar.setDisplayHomeAsUpEnabled(false);
UPDATE:
I test next code with ActionBar sherlock and it's work. There is no back arrow:
getSupportActionBar().setIcon(R.drawable.ic_launcher);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(R.string.about_event_location);
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
You need to add this to your actionBar theme. You can replace arrow image with your own image which can be transparent
<item name="android:homeAsUpIndicator">#drawable/action_arrow</item>
getActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
Where action_arrow is a 25x10px transparent png.
Same code for sherlock would be:
getSupportActionBar().setHomeAsUpIndicator(R.drawable.action_arrow);
#vivek: works great. I do not recommend to use #android:color/transparent as Tim Cooper said, because the Title is aligned to the left. So a empty image is better
In AndroidManifest.xml
remove the below code, which will remove back button from your ActionBar
android:parentActivityName=".Main.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".Main.MainActivity" />
Just keep it like below:
<activity
android:name=".YourActivity"
android:label="#string/your_activity_label">
</activity>

Android: How to set icon in title bar of Dialog activity?

I declared a dialog activity in my Manifest as follows:
<activity android:name=".myDialog"
android:label="#string/title_dlg"
android:icon="#android:drawable/ic_dialog_alert"
android:exported="false"
android:excludeFromRecents="true"
android:theme="#android:style/Theme.Dialog">
However, only the title's text appears in the title bar and the icon appears to be ignored.
Is there a way to also show the icon in the title bar?
Use this after your super.onCreate(savedInstanceState); call:
requestWindowFeature(Window.FEATURE_LEFT_ICON);
Then, set your contentView(R.layout.youLayout);
and then use this:
getWindow().setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, android.R.drawable.ic_dialog_alert);
The order is important.
I think using below line after super call will work
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
Keep in mind to place it before setting content view

Categories

Resources