Hello everyone i create ActionBar. viewpages and custom action bar.Now i want to remove(hide) app icon in ActionBar i used setDisplayShowHomeEnabled(false); but nothing happened. This is a my code
public class MainActivity extends FragmentActivity implements TabListener {
private ViewPager viewPager;
private TabsPagerAdapter mAdapter;
private ActionBar actionBar;
private String[] tabs = { "test1", "test1", "test1", "test1",
"test1" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
actionBar = getActionBar();
actionBar.setHomeButtonEnabled(false);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
//actionBar.setIcon(R.color.white);
actionBar.setDisplayShowTitleEnabled(true);
Drawable d = getResources().getDrawable(R.drawable.acttitle);
getActionBar().setBackgroundDrawable(d);
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
viewPager = (ViewPager) findViewById(R.id.vp_main);
viewPager.setAdapter(mAdapter);
getActionBar().setCustomView(R.layout.menu_example);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM |
ActionBar.DISPLAY_SHOW_HOME );
for (String tab_name : tabs) {
actionBar.addTab(actionBar.newTab().setText(tab_name)
.setTabListener(this));
}
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
actionBar.setSelectedNavigationItem(position);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// actionBar.setStackedBackgroundDrawable(getResources().getDrawable(
// R.drawable.background)); background viewpager
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {
}
@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {
}
}
what is wrong ? if anyone know solution please help me thank you.
If you want to hide Action Bar from the entire application (from all Activities and fragments), then you can use this method. Just go to res -> values -> styles. xml and change the base application to “Theme. AppCompat.
This example demonstrate about how to create a custom action bar in Android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
You use
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
So You Are getting Home icon.
If You want to hide app icon in Particular Activity Use
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
If You want to hide app icon in Full Application Use
setDisplayShowHomeEnabled(false)
and setDisplayShowTitleEnabled(false)
Try this ..
setDisplayShowHomeEnabled(false);
More Reference
UPDATE ::- If you have customized your action bar using XML then you can try some thing like ..
<item name="android:displayOptions"></item>
This eventually will hide your app icon and title ..
As suggested on stack you can also try some combination like ..
getSupportActionBar().setHomeButtonEnabled(false);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setDisplayShowHomeEnabled(false);
getSupportActionBar().setIcon(R.color.transparent);
getSupportActionBar().setDisplayShowTitleEnabled(true);
UPDATE2
Action Bar automatically adjusts every stuff for you. For Ex: If you have lot of stuffs in you title bar then Action Bar adjusts title some thing like YourPr... instead of your complete title like YourProject.
You need not to wonder for that.
UPDATE 3
If some one want to customize ActionBar then it can easily be accomplished like ..
actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.action_bar_confirm_cabs);
fare_ll = (TextView) actionBar.getCustomView().findViewById(
R.id.fare_ll);
confirm_back = (LinearLayout) actionBar.getCustomView().findViewById(
R.id.confirm_cabs_back);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
Then now here you have your textview .. or any thing you wish like you may have a btn over here ..
Simply now apply click listener or any thing you like ..
Hope it helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With