I have an ActionBarDrawerToggle in the ActionBar. My action bar also has a custom view on it. The draw toggle and custom view both appear on KitKat (4.4) API 19
However, on lower versions (for example 4.1 API 16), the custom view in my action bar completely obscures the drawer toggle.
Working fine on 4.4 (Google Nexus 5):
How it looks on 4.1 (Google Nexus 4) (Notice the drawer missing on the left):
Wondering what can I do in this situation? Has anyone encountered this problem?
(Please note: I am not using actionbar sherlock, just the default one)
Thanks!
it works for me
getActionBar().setBackgroundDrawable(
new ColorDrawable(Color.parseColor("yourcolor here"))); //$NON-NLS-1$
LayoutInflater inflator = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ActionBar actionBar = getActionBar();
getActionBar().setDisplayShowCustomEnabled(true);
actionBar.setDisplayShowTitleEnabled(false);
// actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
// getActionBar().setIcon(R.drawable.ic_navigation_drawer);
// navigation icon on actionbar
actionBar.setHomeButtonEnabled(true);
actionBar.setIcon(null);
View actionBarView = inflator.inflate(R.layout.actionbar_custom_layout, null);
getActionBar().setCustomView(actionBarView);
Related
as you can see in the picture below, the white space lays between status bar and actionbar. I normally include android.support.v7.widget.Toolbar with TextView and then I set supportActionbar in MainActivity.
This bug happens only on Sony phone with android 6.0
Try this code
ActionBar actionBar = getActionBar();
if(actionBar !=null)
{
actionBar.hide();
}
I am able to do this but I now can not click the logo. It doesn't fire onOptionsItemSelected()..
actionBar= getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setTitle("");
actionBar.setLogo(R.drawable.logo);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(false);
actionBar.setHomeButtonEnabled(true);
if i set actionBar.setDisplayHomeAsUpEnabled(true); the arrow shows up. I have found a clone of this question, on SO but no one answered it correctly. Someone suggested using a transparent image for teh arrow but how do I override that?
I got it, use
setHomeAsUpIndicator()
Like this:
ActionBar actionBar = getSupportActionBar();
actionBar.setHomeAsUpIndicator(R.drawable.logo);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
I am setting up my Toolbar in my main activity and trying to change the background color with different fragments.
So basically, I am trying to access the Toolbar object inside fragment and set different background color.
Few things which I have tried to do is :
Access toolbar like:
((ActionBarActivity)getActivity()).getSupportActionBar().setBackgroundColor(XXX);
But I am unable to access the setBackgroundColor function inside fragment. It is perfectly working inside the Main Activity.
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
or
ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
Have a look This or This
It is very easy to change the ToolBar, Actionbar color.
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable("COLOR"));
or
ActionBar bar = getSupportActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#0000ff")));
Can I design my Android ActionBar like this?
If yes, give me a starter. I am not new to android design.
Application name with logo is already centered but the little red strip on bottom is difficult as fas as I can understand. If somebody can help.
create custom layout and design whatever you want then add that layout into the actionbar object.
ActionBar actionBar = getSupportActionBar(); //to support lower version too
actionBar.setDisplayShowCustomEnabled(true);
View customView=getLayoutInflater().inflate(R.layout.yourlayout, null);
actionBar.setCustomView(customView);
Create a custom layout according to your requirement in an xml file say,
activity_custom_actionbar.xml
Then include this in your java file using,
ActionBar actionBar = getActionBar();
actionBar.setCustomView(R.layout.activity_custom_actionbar);
getActionBar().setDisplayShowCustomEnabled(true);
In my application a have an ActionBar with Tabs as navigation mode. I also use a custom View which adds another "line" to the ActionBar. Setup looks like:
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(R.layout.ab);
Typeface font = Typeface.createFromAsset(getAssets(), "cs_regular.ttf");
TextView title = (TextView) actionBar.getCustomView().findViewById(R.id.tvActionTitle);
title.setTypeface(font);
The problem: I do not want an icon to be shown, but when I use actionBar.setDisplayShowHomeEnabled(false); my custom layout gets placed BELOW the Tabs and I need it to be above the Tabs in the ActionBar. Setting it to true places the layout as I need it, but shows the unnecessary icon.. any suggestions?
I assume by icon you mean the app icon. You can essentially make it invisible using styles. Add this to the style your Activity is using:
<item name="android:icon">#android:color/transparent</item>