Navigation Drawer Without Actionbar, Android
I am trying to implement navigation drawer without any actionbar. I have a small layout at the top of main layout and it looks like below I want that when i will click the button
Solution 1:
Approach 1
if You have Fixed height of your layout the you can set that much of margin from top to ListView
Approach 2
use this method to calculate the height of your RelativeLayout
then
ViewTreeObserverviewTreeObserver= view.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(newOnGlobalLayoutListener() {
@OverridepublicvoidonGlobalLayout() {
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
viewWidth = view.getWidth();
viewHeight = view.getHeight();
}
});
}
then use this to set Runtime margin to ListView
from top
LinearLayout.LayoutParams lp =new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
imageView.setLayoutParams(lp);
Solution 2:
Yes you can create a drawer layout without action bar, it is very possible, Just do these following steps:
publicclassNavigationDrawerFragmentextendsFragmentimplementsView.OnClickListener {
View drawerView;
DrawerLayout mDrawerLayout;
ActionBarDrawerToggle mDrawerToggle;
RelativeLayout mRlUBAccLayout, mRlPaymentLayout, mRlAutoPayLayout;
TextView mTvUBAccount, mTvMakePayment, mTvAutoPay;
DialogClass mDialog;
@OverridepublicViewonCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
drawerView = inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
mRlUBAccLayout = (RelativeLayout) drawerView.findViewById(R.id.rl_accountlayout);
mRlPaymentLayout = (RelativeLayout) drawerView.findViewById(R.id.rl_mkpaymentlayout);
mRlAutoPayLayout = (RelativeLayout) drawerView.findViewById(R.id.rl_autppaylayout);
mTvUBAccount = (TextView) drawerView.findViewById(R.id.tv_ubaccount);
mTvMakePayment = (TextView) drawerView.findViewById(R.id.tv_mkpayment);
mTvAutoPay = (TextView) drawerView.findViewById(R.id.tv_autopay);
mRlPaymentLayout.setOnClickListener(this);
mRlUBAccLayout.setOnClickListener(this);
mRlAutoPayLayout.setOnClickListener(this);
return drawerView;
}
publicvoidshowDrawer(DrawerLayout drawerLayout) {
mDrawerLayout = drawerLayout;
mDrawerToggle = newActionBarDrawerToggle(getActivity(), drawerLayout, R.string.drawer_open, R.string.drawer_close) {
@OverridepublicvoidonDrawerOpened(View drawerView) {
getActivity().invalidateOptionsMenu();
super.onDrawerOpened(drawerView);
}
@OverridepublicvoidonDrawerClosed(View drawerView) {
getActivity().invalidateOptionsMenu();
super.onDrawerClosed(drawerView);
}
@OverridepublicvoidonDrawerSlide(View drawerView, float slideOffset) {
super.onDrawerSlide(drawerView, slideOffset);
if(HomeFragmentActivity.defaultInstantance().viewingFragment == HomeFragmentActivity.Fragments.ACCOUNT_FRAGMENT){
setNavDrawerColor(0);
}elseif(HomeFragmentActivity.defaultInstantance().viewingFragment == HomeFragmentActivity.Fragments.PAYMENT_FRAGMENT){
setNavDrawerColor(1);
}elseif(HomeFragmentActivity.defaultInstantance().viewingFragment == HomeFragmentActivity.Fragments.AUTOPAY_FRAGMENT){
setNavDrawerColor(2);
}
}
};
mDrawerLayout.setDrawerListener(mDrawerToggle);
mDrawerLayout.post(newRunnable() {
@Overridepublicvoidrun() {
mDrawerToggle.syncState();
}
});
}
}
From your activity call this method showDrawer(Drawerlayout)
. And add this code in the xml for the view which shows the drawer layout:
<fragment
android:id="@+id/fr_navdrawer"
android:name="apjenius.vinton.NavigationDrawerFragment"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
and find the fragment for navigation drawer in the activity using the below code:
mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager().findFragmentById(R.id.fr_navdrawer);
mNavigationDrawerFragment.showDrawer((DrawerLayout) findViewById(R.id.dw_drawerLayout));
Solution 3:
Try to set the height and the width of the action bar =0dp from layout app_bar_.. so it will not effect on the code but will remove the action bar like this
<android.support.v7.widget.Toolbarandroid:id="@+id/toolbar"android:layout_width="0dp"android:layout_height="0dp"android:background="?attr/colorPrimary"app:popupTheme="@style/AppTheme.PopupOverlay" />
Post a Comment for "Navigation Drawer Without Actionbar, Android"