本文整理汇总了Java中android.support.v4.widget.DrawerLayout类的典型用法代码示例。如果您正苦于以下问题:Java DrawerLayout类的具体用法?Java DrawerLayout怎么用?Java DrawerLayout使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DrawerLayout类属于android.support.v4.widget包,在下文中一共展示了DrawerLayout类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initializeDrawer
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
private void initializeDrawer() {
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, mDrawer, mToolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
mDrawer.addDrawerListener(toggle);
toggle.syncState();
mNavigationView = (NavigationView) findViewById(R.id.nav_view);
mNavigationView.setNavigationItemSelectedListener(this);
// Version
TextView appVersion = (TextView) mNavigationView.getHeaderView(0).findViewById(R.id.app_version);
appVersion.setText(getString(R.string.about_version,
Utils.getVersionName(this),
Integer.toString(Utils.getVersionCode(this))));
}
示例2: setTranslucentForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
/**
* 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用)
*
* @param activity 需要设置的activity
* @param drawerLayout DrawerLayout
*/
@Deprecated
public static void setTranslucentForDrawerLayoutDiff(Activity activity,
DrawerLayout drawerLayout)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
{
// 设置状态栏透明
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 设置内容布局属性
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
contentLayout.setFitsSystemWindows(true);
contentLayout.setClipToPadding(true);
// 设置抽屉布局属性
ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
vg.setFitsSystemWindows(false);
// 设置 DrawerLayout 属性
drawerLayout.setFitsSystemWindows(false);
}
}
示例3: setupDrawerLayout
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
private void setupDrawerLayout() {
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);//侧滑菜单
int openDrawerContentDescRes = R.string.open; //菜单显示时的中文描述
int closeDrawerContentDescRes = R.string.close; //菜单关闭时的中文描述
ActionBarDrawerToggle arrowBtn = new ActionBarDrawerToggle(this, drawerLayout, openDrawerContentDescRes, closeDrawerContentDescRes);
//设置显示条件为true
ActionBar actionBar = getSupportActionBar();
//设置显示返回箭头
actionBar.setDisplayHomeAsUpEnabled(true);
//设置显示三横杠
arrowBtn.syncState();
//添加菜单拖动监听事件 根据菜单的拖动距离 将距离折算成旋转角度
drawerLayout.addDrawerListener(arrowBtn);
//处理旋转按钮的点击事件。注意这个控件ID为 android.R.id.home
}
示例4: onCreate
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
if(drawerLayout != null){
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawerLayout, toolbar, R.string.nav_opened, R.string.nav_closed);
drawerLayout.addDrawerListener(toggle);
if(getSupportActionBar() != null) getSupportActionBar().setHomeButtonEnabled(true);
toggle.syncState();
}
if(navigationView != null){
navigationView.setNavigationItemSelectedListener(this);
}
}
示例5: setColorForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
/**
* 为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);
}
}
示例6: onNavigationItemSelected
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
int id = item.getItemId();
if (id == R.id.n_home) {
setFragment(new Tab0Home(), getString(R.string.td_main),"");
} else if (id == R.id.n_news) {
setFragment(new TabBrowser(), getString(R.string.td_news),"");
} else if (id == R.id.n_drivers) {
setFragment(new Tab2Drivers(), getString(R.string.td_drivers),"");
} else if (id == R.id.n_stats) {
setFragment(new Tab3Stats(), getString(R.string.td_stats),"");
} else if (id == R.id.n_guide) {
setFragment(new TabBrowser(), getString(R.string.td_guide), getString(R.string.link_guide));
} else if (id == R.id.n_rules) {
setFragment(new TabBrowser(), getString(R.string.td_rules), getString(R.string.link_rules));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例7: onBackPressed
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@Override
public void onBackPressed()
{
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START) || drawer.isDrawerOpen(GravityCompat.END))
{
if (drawer.isDrawerOpen(GravityCompat.START)){
drawer.closeDrawer(GravityCompat.START);
}
if (drawer.isDrawerOpen(GravityCompat.END)){
drawer.closeDrawer(GravityCompat.END);
}
}
else
{
if (mWebView.canGoBack())
{
mWebView.goBack();
}
else
{
showSnackBar("退出?", "确定", 1);
}
}
}
示例8: onNavigationItemSelected
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@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
Intent i=new Intent(MainteachersActivity.this,addstudpicActivity.class);
startActivity(i);
} else if (id == R.id.nav_gallery) {
} else if (id == R.id.nav_manage) {
} else if (id == R.id.nav_share) {
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例9: setStandardOnClick
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
private void setStandardOnClick(View mViewToListen, final Activity mFromActivity, final Class mToClass, final DrawerLayout mDrawerLayout, final View mDrawerView) {
mViewToListen.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (getActivity() instanceof UsageTrackingAppCompatActivity) {
UsageTrackingAppCompatActivity activity = ((UsageTrackingAppCompatActivity) getActivity());
activity.trackEvent(R.string.category_click, R.string.action_navigation_drawer, mToClass.getSimpleName());
}
Intent intent = new Intent(mFromActivity, mToClass);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); // We don't want to use a transition animation
mIntent = intent;
// Close the drawer. This way the intent will be used to launch the next activity,
// as the OnCloseListener will start the activity, now that the mIntent contains an actual reference
mDrawerLayout.closeDrawer(mDrawerView);
}
});
}
示例10: onCreate
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_usuarios_navigation_drawer);
this.setTitle(R.string.nav_usuarios);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_usuarios);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.usuarios_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.usuarios_nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_usuarios);
}
示例11: setTransparentForDrawerLayout
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
/**
* 为 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);
}
示例12: setTranslucentForDrawerLayoutDiff
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
/**
* 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用)
*
* @param activity 需要设置的activity
* @param drawerLayout DrawerLayout
*/
@Deprecated
public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
// 设置状态栏透明
activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// 设置内容布局属性
ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
contentLayout.setFitsSystemWindows(true);
contentLayout.setClipToPadding(true);
// 设置抽屉布局属性
ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
vg.setFitsSystemWindows(false);
// 设置 DrawerLayout 属性
drawerLayout.setFitsSystemWindows(false);
}
}
示例13: onCreate
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
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);
}
示例14: onNavigationItemSelected
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
if (id == R.id.teacher_nav_profile) {
getFragmentManager().beginTransaction().replace(R.id.fragment_container, StudentProfileFragment.newInstance()).commit();
} else if (id == R.id.teacher_nav_attendance) {
getFragmentManager().beginTransaction().replace(R.id.fragment_container, TeacherAttendance.newInstance()).commit();
} else if (id == R.id.teacher_nav_abt_us) {
getFragmentManager().beginTransaction().replace(R.id.fragment_container, AboutUs.newInstance()).commit();
} else if (id == R.id.teacher_nav_notification) {
getFragmentManager().beginTransaction().replace(R.id.fragment_container, new Notification()).commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
示例15: onCreate
import android.support.v4.widget.DrawerLayout; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicio_navigation_drawer);
this.setTitle(R.string.nav_inicio);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_inicio);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.inicio_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.inicio_nav_view);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setCheckedItem(R.id.nav_inicio);
}