I want to remove from the arrow image from the HomeAsUpButton.
I tried removing the arrow's ImageView from the layout (nothing happens) and also tried using SupportActionBar.SetDisplayHomeAsUpEnabled(false); removes the button functionality entirely.
I'm using johnkil's SideNavigation code. Any suggestions?
Using YouTube's App as example:
With the ActionBar Sherlock, inside your Activity's onCreate method, you just need to do the following:
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
If the up image does not disappear, it might be something related to the library that you referred. In my app, I use the SlidingMenu library and it works just fine (source: https://github.com/jfeinstein10/SlidingMenu)
EDIT: With the SlidingMenu library, the Activity would look like this:
public class MainAct extends SlidingFragmentActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Sliding menu
// Here I set the menu's layout
setBehindContentView(R.layout.menu_frame);
FragmentTransaction t = getSupportFragmentManager().beginTransaction();
MenuListFrag frag = MenuListFrag.newInstance(getSlidingMenuItems());
t.replace(R.id.menu_frame, frag);
t.commit();
// Customizing the SlidingMenu
SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(0.35f);
// Hiding the ActionBar's up button
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
}
}
You can disable the action bar using this method
actionBar.setHomeButtonEnabled(false);
I was able to hide the "arrow" by setting a transparent image.
Related
I have an application, that at the moment only has 2 fragments. Fragment 1, this has the nav drawer and the title.
Fragment 2 requires a custom view as adding menu items won't work as I need alignment. So I add the view as follows:
ActionBar.LayoutParams params = new ActionBar.LayoutParams(
ActionBar.LayoutParams.MATCH_PARENT,
ActionBar.LayoutParams.MATCH_PARENT,
Gravity.LEFT);
//Remove nav drawer "hamburger"
mMainActivity.mActionBarDrawerToggle.setDrawerIndicatorEnabled(false);
//Remove title from Toolbar
bar.setDisplayShowTitleEnabled(false);
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View postToolBar = layoutInflater.inflate(R.layout.upload_content_toolbar, null);
mMainActivity.mToolBar.addView(postToolBar, params);
That is fine and it displays correctly. However, when I want to return to the previous fragment Fragment 1, I then call mMainActivity.mToolBar.removeView(postToolBar); I call this on return to Fragment 1 as the user can navigate either by the back button or by button in the postToolBar. However, the view is still in place. I can't get rid of it. I have now tried setting the visibility to GONE but that won't work either.
This was pretty simple with the Action Bar, however things seem to have gotten a bit complicated with the Tool bar.
I must add that in each of my two fragments I extend a BaseFragment in which I declare the toolbar view.
Can any one help or send me in the direction of a tutorial?
This is how i achieved it at this time:
in activity onCreateView();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowCustomEnabled(true); // enable overriding the default toolbar_home layout
getSupportActionBar().setDisplayShowTitleEnabled(false); // disable the default title element here (for centered title)
getSupportActionBar().setDisplayShowHomeEnabled(false);
cutomToolbarView=getLayoutInflater().inflate(R.layout.custom_toolbar_home, null);
getSupportActionBar().setCustomView(cutomToolbarView);
}
and here is two simple method to do the magic
public void setToolbarTitleEnabled(String title) {
getSupportActionBar().setDisplayShowCustomEnabled(false);
getSupportActionBar().setDisplayShowTitleEnabled(true);
getSupportActionBar().setTitle(title);
}
public void setCustomToolbarEnabled() {
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setDisplayShowTitleEnabled(false);
}
then simply when you can change actionbar like these:
when to select HomeFragment.java or whatever in your case
setToolbarTitleEnabled(CURRENT_TAG);
and when to select other fragment:
setCustomToolbarEnabled();
I am using J.Feinstein library of sliding menu and it works great... The only problem i have is that it closes only if i touch outside the sliding menu or if i swipe from right to left from outside the sliding menu..
But what actually i want is that it will also swipe from right to left to close when i swipe it by finger on it, not only from outside of it...
I searched a lot.. In fact i read the source code of library and found the function getSlidingMenu(true); but that does not fulfill my requirement .. I am new to android... Kindly help me out and tell me how to do this..
Here is my piece of code..
public class ViewPagerActivity extends SlidingFragmentActivity{
// Tab titles
private String[] tabs = { "First", "Second", "Third" };
public ViewPagerActivity() {
super();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(R.string.viewpager);
setContentView(R.layout.pager);
// customize the SlidingMenu
final SlidingMenu sm = getSlidingMenu();
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setShadowDrawable(R.drawable.shadow);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setFadeDegree(0.35f);
sm.setScrollBarStyle(2);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
//sm.setSlidingEnabled(true);
//sm.setTouchmodeMarginThreshold(2);
getSlidingMenu().setSlidingEnabled(true);
setBehindContentView(R.layout.menu_frame);
}
}
If you want this type of sliding then use view pager with sliding....
http://javapapers.com/android/android-image-slider-tutorial/
this will surely help you and you will no have to face this kind of problem...
I'm using the AppCompat/ActionBarCompat library and I need to create a custom ActionBar. I need to open the activity without an ActionBar and enable it only when I add the custom view. How can I do this?
PS: I need to define the activity to not use an ActionBar through the AndroidManifest.xml and my application minimum API level is 10.
.hide() the action bar and then .show() the action bar when your ready for it
import android.support.v7.app.ActionBar;
...
private ActionBar mActionbar;
...
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mActionbar = getSupportActionBar();
mActionbar.hide()
}
...
somewhere when something cool happens
mActionbar.show();
I am developing an app in which i have to use left and right menu.I googled and found SlidingMenu library of #jfeinstein
Things are working fine i am able to open both left and right menu.But The only problem is that the secondry menu opens with unnecessary extra spacing.I need to remove that extra spacing.I have attached the screen shots also.
here spacing is fine
Please let me know the solution.
But here i need to make the content fit inside the menu.
and here is Activity for displaying menu
public class BaseSlidingMenuActivity extends SlidingFragmentActivity {
private int mTitleRes;
protected ListFragment mFrag;
protected SlideLeftMenuFragment mLeftFrag;
/**
* Title for Sliding Menu.
*
* #param titleRes
*/
public BaseSlidingMenuActivity(int titleRes) {
mTitleRes = titleRes;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle(mTitleRes);
// set the Behind View
setBehindContentView(R.layout.menu_frame);
if (savedInstanceState == null) {
FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
mFrag = new SlideRightMenuFragment();
t.replace(R.id.menu_frame, mFrag);
t.commit();
} else {
mFrag = (ListFragment) this.getSupportFragmentManager().findFragmentById(R.id.menu_frame);
}
// customize the SlidingMenu
final SlidingMenu sm = getSlidingMenu();
sm.setMode(SlidingMenu.LEFT_RIGHT);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setShadowWidthRes(R.dimen.shadow_width);
sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
sm.setShadowDrawable(R.drawable.shadow);
sm.setFadeDegree(0.35f);
sm.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
sm.setSecondaryMenu(R.layout.menu_frame_two);
sm.setSecondaryShadowDrawable(R.drawable.shadowright);
mLeftFrag = new SlideLeftMenuFragment();
getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame_two, mLeftFrag).commit();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
// setSlidingActionBarEnabled(false);
}
Thanks in advance
I had forked a new branch to add this feature from jfeinstein's slidemenu.
https://github.com/buptcoder/SlidingMenu
in my branch, I added a new method for SlideMenu.
You can use
sm.setRightBehindOffset(200);
to adjust the right menu's width.
Any problems please let me know.
Hi there I have been using the ViewPagerIndicator library for some time now and I want my action-bar's title to change every time the user swipes to another Fragment to the other pages here is the code I am thinking off but it is just not working.
Activity miz = getActivity();
miz.setTitle("Miz");
I have put this code in all my Fragments displaying different titles every time but for some reason it is not working properly as it is always late. I think it may have something to do with the OnCreate , OnResume or OnPause and can not lay a finger on it can some one help ? I want the Title of the Action Bar to change while the next Fragment is visible to the user.
I have also though of some code like this
#Override
public void onResume() {
// TODO Auto-generated method stub
super.onResume();
Activity miz = getActivity();
miz.setTitle("Miz");
}
Regular :
this.getActivity().getActionBar().setTitle(title);
With ActioBarSherlock :
this.getSherlockActivity().getSupportActionBar().setTitle(title);
You can do this:
ActionBar actionBar = getActionBar(); // or getSupportActionBar() for ActionBarSherlock
actionBar.setTitle("test");
In a Fragment:
ActionBar actionBar = getActivity().getActionBar();
actionBar.setTitle("test");
Try
((AppCompatActivity) getActivity()).getSupportActionBar().setTitle("Miz");
It will work
Reference: Setting a subtitle on my Toolbar from a fragment