国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android5.0 旋轉(zhuǎn)菜單實例詳解

2019-12-12 04:16:23
字體:
供稿:網(wǎng)友

先給大家展示下效果圖:

這里寫圖片描述

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

上面的效果圖 用 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"><!--標(biāo)題欄-->  <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);    //設(shè)置toobar為標(biāo)題欄    setSupportActionBar(toobar);    //設(shè)置顯示旋轉(zhuǎn)菜單    getSupportActionBar().setDisplayHomeAsUpEnabled(true);    //抽屜布局    drawerLayout = ((DrawerLayout) findViewById(R.id.activity_main));    //activitybar開關(guān)    actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.app_name, R.string.app_name);    //同步開關(guān) 如果不寫的話, 滑動開關(guān) 按鈕一直就一個狀態(tài) 不會變化    actionBarDrawerToggle.syncState();    //添加監(jiān)聽    drawerLayout.addDrawerListener(actionBarDrawerToggle);  }  @Override  public boolean onOptionsItemSelected(MenuItem item) {    //這里是讓用戶點擊按鈕的時候可以打開抽屜    return actionBarDrawerToggle.onOptionsItemSelected(item)        || super.onOptionsItemSelected(item);  }}

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 治县。| 罗江县| 龙海市| 宁德市| 桓台县| 杨浦区| 临澧县| 福清市| 内江市| 河南省| 丰都县| 噶尔县| 新营市| 鹤岗市| 金乡县| 监利县| 额尔古纳市| 海晏县| 广汉市| 兴隆县| 博白县| 布尔津县| 邵东县| 楚雄市| 台中县| 盐山县| 虎林市| 贡山| 阿合奇县| 叶城县| 嵩明县| 武汉市| 中宁县| 宁强县| 蒙城县| 靖西县| 维西| 若尔盖县| 三都| 罗江县| 双鸭山市|