android.support.v4.widget.DrawerLayout Java Examples

The following examples show how to use android.support.v4.widget.DrawerLayout. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From Puff-Android with MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {

    Category category = CategoryHelper.getInstance(getApplicationContext())
            .getCategoryByName(String.valueOf(item.getTitle()));
    loadAccountByCategory(category);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (headerImageView != null)
        Picasso.with(this).load(ResUtil.getInstance(null).getBmpUri(category.getIcon()))
                .config(Bitmap.Config.RGB_565)
                .fit()
                .into(headerImageView);
    if (headerTextView != null)
        headerTextView.setText(category.getName());
    drawer.closeDrawer(GravityCompat.START);
    if (lastChecked != null)
        lastChecked.setChecked(false);
    item.setChecked(true);
    lastChecked = item;
    return true;
}
 
Example #2
Source File: MainActivity.java    From blade-player with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onBackPressed()
{
    // Handle drawer close
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START))
    {
        drawer.closeDrawer(GravityCompat.START);
    }
    else if(backBundles.size() != 0)
    {
        restoreInstanceState(backBundles.get(backBundles.size()-1), backObjects.get(backObjects.size()-1));
        backBundles.remove(backBundles.size()-1);
        backObjects.remove(backObjects.size()-1);
    }
    else
    {
        super.onBackPressed();
    }
}
 
Example #3
Source File: StatusBarUtil.java    From FileManager with Apache License 2.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity 需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color 状态栏颜色值
 */
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout,
    int color) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    // 生成一个状态栏大小的矩形
    View statusBarView = createStatusBarView(activity, color);
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    contentLayout.addView(statusBarView, 0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
      contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }
    // 设置属性
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
  }
}
 
Example #4
Source File: ImmersionBar.java    From MNImageBrowser with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 检查布局根节点是否使用了android:fitsSystemWindows="true"属性
 * Check fits system windows boolean.
 *
 * @param view the view
 * @return the boolean
 */
public static boolean checkFitsSystemWindows(View view) {
    if (view == null) {
        return false;
    }
    if (view.getFitsSystemWindows()) {
        return true;
    }
    if (view instanceof ViewGroup) {
        ViewGroup viewGroup = (ViewGroup) view;
        for (int i = 0, count = viewGroup.getChildCount(); i < count; i++) {
            View childView = viewGroup.getChildAt(i);
            if (childView instanceof DrawerLayout) {
                if (checkFitsSystemWindows(childView)) {
                    return true;
                }
            }
            if (childView.getFitsSystemWindows()) {
                return true;
            }
        }
    }
    return false;
}
 
Example #5
Source File: XStatusBar.java    From XFrame with Apache License 2.0 6 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
}
 
Example #6
Source File: StatusBarUtil.java    From MaoWanAndoidClient with Apache License 2.0 6 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
}
 
Example #7
Source File: HomeActivity.java    From ZZShow with Apache License 2.0 6 votes vote down vote up
@Override
public void initViews() {
    mDrawerLayout.addDrawerListener(new DrawerLayout.SimpleDrawerListener() {
        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            if(isSwitchNight && ismIsAddedView()){
                setIsAddedView(false);
                getWindow().setWindowAnimations(R.style.WindowAnimationFadeInOut);
                KLog.d("NightMode"," - recreate - ");
                recreate();
            }
        }
    });

    mNavigationView.setNavigationItemSelectedListener(this);
    initNightModeSwitch();
    childFragmentType = childFragmentType == null ? CHILD_FRAGMENT_TAG_NEWS : childFragmentType;
    setDefaultChildFragment(childFragmentType);
}
 
Example #8
Source File: StatusBarUtil.java    From FimiX8-RE with MIT License 6 votes vote down vote up
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (VERSION.SDK_INT >= 19) {
        if (VERSION.SDK_INT >= 21) {
            activity.getWindow().addFlags(Integer.MIN_VALUE);
            activity.getWindow().clearFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
            activity.getWindow().setStatusBarColor(0);
        } else {
            activity.getWindow().addFlags(NTLMConstants.FLAG_UNIDENTIFIED_9);
        }
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (!((contentLayout instanceof LinearLayout) || contentLayout.getChildAt(1) == null)) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        setDrawerLayoutProperty(drawerLayout, contentLayout);
    }
}
 
Example #9
Source File: RxDrawer.java    From SeeWeather with Apache License 2.0 6 votes vote down vote up
public static Observable<Irrelevant> close(final DrawerLayout drawer) {
    return Observable.create(emitter -> {
        drawer.closeDrawer(GravityCompat.START);
        DrawerListener listener = new DrawerLayout.SimpleDrawerListener() {
            @Override
            public void onDrawerSlide(View drawerView, float slideOffset) {
                if (slideOffset < OFFSET_THRESHOLD) {
                    emitter.onNext(Irrelevant.INSTANCE);
                    emitter.onComplete();
                    drawer.removeDrawerListener(this);
                }
            }
        };
        drawer.addDrawerListener(listener);
    });
}
 
Example #10
Source File: MainActivity.java    From funcodetuts with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    // Code here will be triggered once the drawer closes as we don't want anything to happen so we leave this blank
    mActionBarDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
            toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);

    //calling sync state is necessary or else your hamburger icon wont show up
    mActionBarDrawerToggle.syncState();

    if (savedInstanceState == null) {
        // update the main content by replacing fragments
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
        FragmentTransaction transaction = fragmentManager.beginTransaction();

        transaction.replace(R.id.container, new ContainerFragment());
        transaction.commit();
    }
}
 
Example #11
Source File: Activity_Main.java    From FoodOrdering with Apache License 2.0 6 votes vote down vote up
/**
 * 先加载不需要动态获取数据的静态布局,有利于用户体验
 */
private void initStaticView() {
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    navView = (NavigationView) findViewById(R.id.nav_view);
    bottomNavigationBar = (BottomNavigationBar) findViewById(R.id.bottom_navigation_bar);
    toolbar.setTitle("");
    toolbarText = (TextView) findViewById(R.id.toolbar_text);
    toolbarText.setText("首页");

    setSupportActionBar(toolbar);//使用toolbar,外观功能和ActionBar一致
    final ActionBar actionBar = getSupportActionBar();//得到ActionBar实例
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);//让导航按钮显示出来
        actionBar.setHomeAsUpIndicator(R.mipmap.ic_menu);//设置导航按钮图标
    }
    //加载底部导航栏及选中事件
    loadBottomNavigationBar();
}
 
Example #12
Source File: BrowserActivity.java    From Cybernet-VPN with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId();

    if (id == R.id.nav_camera) {
        // Handle the camera action
    } else if (id == R.id.nav_gallery) {

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawer.closeDrawer(GravityCompat.START);
    return true;
}
 
Example #13
Source File: HomeActivity.java    From SensorsAndAi with MIT License 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    int id = item.getItemId ();

    if (id == R.id.nav_camera) {
        // Handle the camera action
    } else if (id == R.id.nav_gallery) {
        startActivity ( new Intent ( HomeActivity.this,About_us.class ) );

    } else if (id == R.id.nav_slideshow) {

    } else if (id == R.id.nav_manage) {

    } else if (id == R.id.nav_share) {

    } else if (id == R.id.nav_send) {

    }

    DrawerLayout drawer = (DrawerLayout) findViewById ( R.id.drawer_layout );
    drawer.closeDrawer ( GravityCompat.START );
    return true;
}
 
Example #14
Source File: MainActivity.java    From kute with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.landing);

    // Set a Toolbar to replace the ActionBar.
    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    // Find our drawer view
    mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);

    // Find our drawer view
    nvDrawer = (NavigationView) findViewById(R.id.nvView);
    // Setup drawer view
    setupDrawerContent(nvDrawer);



}
 
Example #15
Source File: StatusBarUtil.java    From TLint with Apache License 2.0 6 votes vote down vote up
/**
 * 为 DrawerLayout 布局设置状态栏透明
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 */
public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }

    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
    }

    // 设置属性
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    contentLayout.setFitsSystemWindows(false);
    contentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
}
 
Example #16
Source File: MainActivity.java    From miappstore with Apache License 2.0 6 votes vote down vote up
@Override
protected void initToolBar() {
    super.initToolBar();
    view = View.inflate(this, R.layout.activity_main, null);
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayout) view.findViewById(R.id.drawer_layout);
    toolbar.setBackgroundColor(getResources().getColor(R.color.light_toolbar));
    toolbar.setTitle("应用商店");
    toolbar.setLogo(R.mipmap.logo);//设置Logo
    setSupportActionBar(toolbar);
    ActionBarDrawerToggle drawerToggle = new ActionBarDrawerToggle(
            this, drawerLayout, toolbar, R.string.app_name, R.string.app_name
    );
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();
}
 
Example #17
Source File: MainActivity.java    From wshell with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
	switch (item.getItemId()) {
		case R.id.nav_settings:
			Intent intent_settings = new Intent(this, SettingsActivity.class);
			startActivity(intent_settings);
			break;
		case R.id.nav_about:
			Intent intent_about = new Intent(this, AboutActivity.class);
			startActivity(intent_about);
			break;
		case R.id.nav_exit:
			finish();
			break;
	}
	DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
	drawer.closeDrawer(GravityCompat.START);
	return true;
}
 
Example #18
Source File: StatusBarUtil.java    From ByWebView with Apache License 2.0 6 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
 *
 * @param activity     需要设置的activity
 * @param drawerLayout DrawerLayout
 * @param color        状态栏颜色值
 */
@Deprecated
public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // 生成一个状态栏大小的矩形
        ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
        if (contentLayout.getChildCount() > 0 && contentLayout.getChildAt(0) instanceof StatusBarView) {
            contentLayout.getChildAt(0).setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
        } else {
            // 添加 statusBarView 到布局中
            StatusBarView statusBarView = createStatusBarView(activity, color);
            contentLayout.addView(statusBarView, 0);
        }
        // 内容布局不是 LinearLayout 时,设置padding top
        if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
            contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
        }
        // 设置属性
        ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
        drawerLayout.setFitsSystemWindows(false);
        contentLayout.setFitsSystemWindows(false);
        contentLayout.setClipToPadding(true);
        drawer.setFitsSystemWindows(false);
    }
}
 
Example #19
Source File: HomeActivity.java    From Hillffair17 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed(){
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #20
Source File: MainActivity.java    From block-this with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Fabric.with(this, new Answers(), new Crashlytics());
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    if (Build.VERSION.SDK_INT<21) {
        Menu nav_menu = navigationView.getMenu();
        nav_menu.findItem(R.id.nav_whitelist).setVisible(false);
    }

    WVersionManager versionManager = new WVersionManager(this);
    versionManager.setVersionContentUrl("https://block-this.com/version.txt");
    versionManager.setUpdateUrl("https://block-this.com/block-this-latest.apk");
    versionManager.setDialogCancelable(false);
    versionManager.setReminderTimer(720);
    versionManager.setIgnoreThisVersionLabel(""); //make button invisible
    versionManager.checkVersion();

    //Initiate shared preferences
    sharedPreferences = this.getSharedPreferences("com.savageorgiev.blockthis", Context.MODE_PRIVATE);
    displaySelectedScreen(R.id.nav_home);
}
 
Example #21
Source File: MainActivity.java    From Alexei with Apache License 2.0 5 votes vote down vote up
private void configure() {
    mNavigationDrawerFragment = (NavigationDrawerFragment)
            getFragmentManager().findFragmentById(R.id.navigation_drawer);

    mNavigationDrawerFragment.setUp(
            R.id.navigation_drawer,
            (DrawerLayout) findViewById(R.id.drawer_layout));
}
 
Example #22
Source File: MenuActivity.java    From dhis2-android-datacapture with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_menu);

    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.navigation_view);
    if (navigationView != null) {
        navigationView.inflateMenu(R.menu.menu_drawer);
        navigationView.setNavigationItemSelectedListener(this);
    }

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (toolbar != null) {
        toolbar.setNavigationIcon(R.drawable.ic_menu);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggleNavigationDrawer();
            }
        });
    }

    if (savedInstanceState == null) {
        onNavigationItemSelected(navigationView.getMenu()
                .findItem(R.id.drawer_item_aggregate_report));
    } else if (savedInstanceState.containsKey(STATE_TOOLBAR_TITLE) && toolbar != null) {
        setTitle(savedInstanceState.getString(STATE_TOOLBAR_TITLE));
    }

    if(ViewUtils.fragmentSelected != null) {
        attachFragment(ViewUtils.fragmentSelected);
        setTitle(ViewUtils.title);
    }
}
 
Example #23
Source File: StatusBarUtil.java    From StatusBarManager with Apache License 2.0 5 votes vote down vote up
/**
 * 设置 DrawerLayout 属性
 *
 * @param drawerLayout              DrawerLayout
 * @param drawerLayoutContentLayout DrawerLayout 的内容布局
 */
private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) {
    ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
    drawerLayout.setFitsSystemWindows(false);
    drawerLayoutContentLayout.setFitsSystemWindows(false);
    drawerLayoutContentLayout.setClipToPadding(true);
    drawer.setFitsSystemWindows(false);
}
 
Example #24
Source File: MainVu.java    From FlyWoo with Apache License 2.0 5 votes vote down vote up
/**
 * findView操作
 */
private void bindViews() {
    mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
    createButton = (ImageView) view.findViewById(R.id.createButton);
    tv_select_size = (TextView) view.findViewById(R.id.tv_select_size);

    drawer = (DrawerLayout) view.findViewById(R.id.drawer);

    ib_menu = (ImageButton) view.findViewById(R.id.ib_menu);
    ib_more = (ImageButton) view.findViewById(R.id.ib_more);
    ib_search = (ImageButton) view.findViewById(R.id.ib_search);

    layout_bottom = view.findViewById(R.id.layout_bottom);
    ib_more.setOnClickListener(this);
}
 
Example #25
Source File: HomeActivity.java    From microbit with Apache License 2.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if(drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #26
Source File: SensorDataTable.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onResume(){
    super.onResume();
    mNavigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), menu_name, this);
    getData();
}
 
Example #27
Source File: MainActivity.java    From TimeTable with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #28
Source File: MainActivity.java    From FloorListView with MIT License 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #29
Source File: BaseActivity.java    From privacy-friendly-weather with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onBackPressed() {
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    if (drawer.isDrawerOpen(GravityCompat.START)) {
        drawer.closeDrawer(GravityCompat.START);
    } else {
        super.onBackPressed();
    }
}
 
Example #30
Source File: UIStatusBarController.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 为DrawerLayout 布局设置状态栏变色
 *
 * @param activity       需要设置的activity
 * @param drawerLayout   DrawerLayout
 * @param color          状态栏颜色值
 * @param statusBarAlpha 状态栏透明度
 */
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
                                           @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
    } else {
        activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
    }
    // 生成一个状态栏大小的矩形
    // 添加 statusBarView 到布局中
    ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
    View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
    if (fakeStatusBarView != null) {
        if (fakeStatusBarView.getVisibility() == View.GONE) {
            fakeStatusBarView.setVisibility(View.VISIBLE);
        }
        fakeStatusBarView.setBackgroundColor(color);
    } else {
        contentLayout.addView(createStatusBarView(activity, color), 0);
    }
    // 内容布局不是 LinearLayout 时,设置padding top
    if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
        contentLayout.getChildAt(1)
                .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
                        contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
    }
    // 设置属性
    setDrawerLayoutProperty(drawerLayout, contentLayout);
    addTranslucentView(activity, statusBarAlpha);
}