Android5.0 旋轉(zhuǎn)菜單實(shí)例詳解
先給大家展示下效果圖:

這個(gè)效果是安卓5.0推出 “材料設(shè)計(jì)” Ui效果 以前一直沒留意到,寫篇文章當(dāng)成備忘錄
上面的效果圖 用 DrawerLayout和Toolbar實(shí)現(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) 如果不寫的話, 滑動(dòng)開關(guān) 按鈕一直就一個(gè)狀態(tài) 不會(huì)變化
actionBarDrawerToggle.syncState();
//添加監(jiān)聽
drawerLayout.addDrawerListener(actionBarDrawerToggle);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
//這里是讓用戶點(diǎn)擊按鈕的時(shí)候可以打開抽屜
return actionBarDrawerToggle.onOptionsItemSelected(item)
|| super.onOptionsItemSelected(item);
}
}
相關(guān)文章
Android代碼實(shí)現(xiàn)圖片和文字上下布局
在Android開發(fā)中經(jīng)常會(huì)需要用到帶文字和圖片的button,下面來給大家介紹使用radiobutton實(shí)現(xiàn)圖片和文字上下布局或左右布局。感興趣的朋友一起學(xué)習(xí)吧2015-11-11
Android自定義view仿微信刷新旋轉(zhuǎn)小風(fēng)車
這篇文章主要介紹了Android自定義view仿微信刷新旋轉(zhuǎn)小風(fēng)車,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-12-12
Android中使用AsyncTask實(shí)現(xiàn)文件下載以及進(jìn)度更新提示
AsyncTask,它使創(chuàng)建需要與用戶界面交互的長時(shí)間運(yùn)行的任務(wù)變得更簡單,本篇文章主要介紹了Android中使用AsyncTask實(shí)現(xiàn)文件下載以及進(jìn)度更新提示,有興趣的可以了解一下。2016-12-12
Android SwipeMenuListView框架詳解分析
這篇文章主要介紹了Android SwipeMenuListView框架詳解分析的相關(guān)資料,需要的朋友可以參考下2016-10-10
android開發(fā)教程之使用線程實(shí)現(xiàn)視圖平滑滾動(dòng)示例
這篇文章主要介紹了android使用線程實(shí)現(xiàn)視圖平滑滾動(dòng)示例,需要的朋友可以參考下2014-03-03
Kotlin 高階函數(shù)與Lambda表達(dá)式示例詳解
這篇文章主要為大家介紹了Kotlin 高階函數(shù)與Lambda表達(dá)式示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-12-12

