當前位置: 首頁>>代碼示例>>Java>>正文


Java DrawerLayout類代碼示例

本文整理匯總了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))));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:MainActivity.java

示例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);
    }
}
 
開發者ID:Ayvytr,項目名稱:EasyAndroid,代碼行數:26,代碼來源:BarTool.java

示例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
    }
 
開發者ID:lianghao208,項目名稱:InstaFlickr,代碼行數:18,代碼來源:MainActivity.java

示例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);
    }
}
 
開發者ID:oragamihawk,項目名稱:OpenOrbitCNCAndroidFrontend,代碼行數:20,代碼來源:BaseNavActivity.java

示例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);
    }
}
 
開發者ID:joelan,項目名稱:ClouldReader,代碼行數:33,代碼來源:StatusBarUtil.java

示例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;
}
 
開發者ID:YoungPeacock,項目名稱:FantaF1,代碼行數:23,代碼來源:MainActivity.java

示例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);
		}
       }
   }
 
開發者ID:gtf35,項目名稱:easyShopping,代碼行數:26,代碼來源:Main.java

示例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;
}
 
開發者ID:iamjaspreetsingh,項目名稱:TrackPlan-app,代碼行數:24,代碼來源:MainteachersActivity.java

示例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);
		}
	});
}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:21,代碼來源:NavigationDrawerFragment.java

示例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);
}
 
開發者ID:EdwardAlexis,項目名稱:Sistema-de-Comercializacion-Negocios-Jhordan,代碼行數:20,代碼來源:Usuarios.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:32,代碼來源:StatusBarUtil.java

示例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);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:StatusBarUtil.java

示例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);
}
 
開發者ID:LSL-Git,項目名稱:Test,代碼行數:26,代碼來源:MainActivity.java

示例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;
}
 
開發者ID:akshah1997,項目名稱:OSTMiniProject,代碼行數:21,代碼來源:TeacherNavigation.java

示例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);

}
 
開發者ID:EdwardAlexis,項目名稱:Sistema-de-Comercializacion-Negocios-Jhordan,代碼行數:21,代碼來源:Inicio.java


注:本文中的android.support.v4.widget.DrawerLayout類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。