欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android5.0 旋轉菜單實例詳解

 更新時間:2016年12月20日 14:42:04   作者:安兒IT  
這篇文章主要介紹了 Android5.0 旋轉菜單的相關資料,非常不錯,具有參考借鑒價值,需要的朋友參考下

先給大家展示下效果圖:

這里寫圖片描述

這個效果是安卓5.0推出 “材料設計” Ui效果 以前一直沒留意到,寫篇文章當成備忘錄

上面的效果圖 用 DrawerLayout和Toolbar實現(xiàn)

布局如下

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="#fff0ff"
  android:orientation="vertical"
  tools:context="a.fmy.com.myapplication.MainActivity">
<!--標題欄-->
  <android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?attr/colorPrimary"
    android:minHeight="?attr/actionBarSize" />
  <android.support.v4.widget.DrawerLayout
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#0ff"
   >
    <!--內(nèi)容-->
    <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#ff0"></LinearLayout>
    <!--菜單-->
    <LinearLayout
      android:layout_width="200dp"
      android:layout_height="match_parent"
      android:layout_gravity="start"
      android:background="#f0f" />
  </android.support.v4.widget.DrawerLayout>
</LinearLayout>

activity 代碼

public class MainActivity extends AppCompatActivity {
  private Toolbar toobar;
  private ActionBarDrawerToggle actionBarDrawerToggle;
  private DrawerLayout drawerLayout;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    toobar = (Toolbar) findViewById(R.id.toolbar);
    //設置toobar為標題欄
    setSupportActionBar(toobar);
    //設置顯示旋轉菜單
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    //抽屜布局
    drawerLayout = ((DrawerLayout) findViewById(R.id.activity_main));
    //activitybar開關
    actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.app_name, R.string.app_name);
    //同步開關 如果不寫的話, 滑動開關 按鈕一直就一個狀態(tài) 不會變化
    actionBarDrawerToggle.syncState();
    //添加監(jiān)聽
    drawerLayout.addDrawerListener(actionBarDrawerToggle);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    //這里是讓用戶點擊按鈕的時候可以打開抽屜
    return actionBarDrawerToggle.onOptionsItemSelected(item)
        || super.onOptionsItemSelected(item);
  }
}

相關文章

最新評論