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); } }
相關文章
Android中使用AsyncTask實現(xiàn)文件下載以及進度更新提示
AsyncTask,它使創(chuàng)建需要與用戶界面交互的長時間運行的任務變得更簡單,本篇文章主要介紹了Android中使用AsyncTask實現(xiàn)文件下載以及進度更新提示,有興趣的可以了解一下。2016-12-12Android SwipeMenuListView框架詳解分析
這篇文章主要介紹了Android SwipeMenuListView框架詳解分析的相關資料,需要的朋友可以參考下2016-10-10android開發(fā)教程之使用線程實現(xiàn)視圖平滑滾動示例
這篇文章主要介紹了android使用線程實現(xiàn)視圖平滑滾動示例,需要的朋友可以參考下2014-03-03Kotlin 高階函數(shù)與Lambda表達式示例詳解
這篇文章主要為大家介紹了Kotlin 高階函數(shù)與Lambda表達式示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-12-12