how to override default action bar with custom layout actionbar - android

I try to get rid of default action bar by load a custom action bar. But then, it become like this :
FYI : this project is including navigation drawer sidebar. I am not really sure if the gray block thingy come from navigation drawer.

try like this it may helpful
ActionBar actionBar = getActionBar();
actionBar.setTitle("Project1");
actionBar.setDisplayOptions(actionBar.getDisplayOptions()
| ActionBar.DISPLAY_SHOW_CUSTOM);
LayoutInflater inflater = (LayoutInflater) getActionBar()
.getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(
R.layout.custom_actionbar, null);
actionBar.setCustomView(customActionBarView);
here custom_actionbar is the xml file to add items in actionbar(like text,images and all)

Related

How can I change the ActionBar color of individual fragments in Android?

Is there any way to change the ActionBar color of fragments and change the title displayed in the ActionBar to the title of the menu option that was pressed?
If you are using AppCompat you always have to call getSupportActionBar()
Change Title :
getSupportActionBar().setTitle("Your Title");
Change Color :
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(Color.YOUR_COLOR));
If in Fragment :
Change Title :
getActivity().getActionBar().setTitle("YOUR TITLE");
Change Color :
getActivity().getAcationBar().setBackgroundDrawable(new ColorDrawable(Color.YOUR_COLOR));
Hope this help you
This is the suggested answer written in java :
getActionBar().setTitle("Test");
getActionBar().setBackgroundDrawable(new ColorDrawable("COLOR"));
If you're using support libraries:
android.support.v7.app.ActionBar supportActionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setTitle("My action bar title");
View view = new View(getContext());
view.setBackgroundColor(getResources().getColor(R.color.my_color));
supportActionBar.setBackgroundDrawable(view.getBackground());
}
Otherwise:
android.app.ActionBar actionBar = getActivity().getActionBar();
if (actionBar != null) {
actionBar.setTitle("My action bar title");
View view = new View(getContext());
view.setBackgroundColor(getResources().getColor(R.color.my_color));
actionBar.setBackgroundDrawable(view.getBackground());
}

Prevent clicks on actionbar menu

I want to create some animation on my activity and for this reason I need to be able to show the actionbar menu icon (the three dots one) but in same time to block programmatically any click event on it.
I need something alike:
setClicksOnActionbarMenuEnable(false); // any click on my actionbar menu icon will be disabled
doMyAnimation();
setClicksOnActionbarMenuEnable(true); // actionbar menu icon will accept again clicks.
I have searched everywhere and couldn't find any way to accomplish this.
I got this solution:
final Toolbar toolbar = (Toolbar) this.findViewById(R.id.toolbar);
final View child = toolbar.getChildAt(2);
if (child instanceof ActionMenuView)
{
final ActionMenuView actionMenuView = ((ActionMenuView) child);
actionMenuView.getChildAt(actionMenuView.getChildCount() - 1).setEnabled(false);
}
If don't have a navigation drawer replace with:
final View child = toolbar.getChildAt(1);

Navigation drawer icon gets disappeared on setting CustomView in actionbar

Why navigation drawer icon gets disappeared on setting customView by
actionbar.setCustomView(R.layout.blah);
How can this be resolved?
OK, you don't post any code, so I have to assume stuff here. So if you can update your question and show actual code!!
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar actionBar = getActionBar();
// Depending on what your custom Action Bar will do, you might want to disable these!
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
LayoutInflater inflater = LayoutInflater.from(this);
View customView = inflater.inflate(R.layout.custom_actionbar, null);
// Here is how you can get specific items from your custom view!
TextView titleTextView = (TextView) customView.findViewById(R.id.title_text);
titleTextView.setText("My Own Title");
...
// MAKE SURE THESE ARE SET!! BOTH OF THEM!!
actionBar.setCustomView(mCustomView);
actionBar.setDisplayShowCustomEnabled(true);
}
The biggest issue is probably the code at the very end. Please make sure you have that code!

How to remove Action Bar and set the custom title of FragmentActivity of Sherlock

Hello I am using Sherlock library to achieve the Tabs. Here I am looking to remove the ActionBar at the top and set the custom title layout instead of it.
I achieved a functionality to add the Tabs but could not set the custom title over ActionBar. Any way to do this ?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pay_stub);
// adding action bar tabs to the activity
ActionBar mActionBar = getSupportActionBar();
Tab firstTab = mActionBar.newTab().setText(getString(R.string.paystub_current_tab)).setTabListener(this);
Tab secondTab = mActionBar.newTab().setText(getString(R.string.paystub_all_tab)).setTabListener(this);
// add the tabs to the action bar
mActionBar.addTab(firstTab);
mActionBar.addTab(secondTab);
// set the navigation mode the Action Bar Tabs
mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
}
Thanks in advance.
I resolved this by adding background color and icon of the ActionBar.
ActionBar actionBar = getSupportActionBar();
setTitle("");
actionBar.setIcon(R.drawable.headerlogo);
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#F4A401")));

Implement Actionbar in Android Honeycomb

How to implement the ActionBar in android honeycomb? How to customize the action bar? Any help would be appreciated.
try this
ActionBar actionBar = getActionBar();
LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout."id", null);
// lay.setLayoutParams(new ActionBar.LayoutParams(
// android.app.ActionBar.LayoutParams.MATCH_PARENT,
// android.app.ActionBar.LayoutParams.MATCH_PARENT));
//Not wrking
actionBar.setCustomView(view);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
You can also use the following resource to know more about implementing the action bar-
http://developer.android.com/guide/topics/ui/actionbar.html

Categories

Resources