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

Android編程實(shí)現(xiàn)ActionBar的home圖標(biāo)動(dòng)畫切換效果

 更新時(shí)間:2017年01月20日 10:59:45   作者:books1958  
這篇文章主要介紹了Android編程實(shí)現(xiàn)ActionBar的home圖標(biāo)動(dòng)畫切換效果,涉及Android布局、樣式、Activity及菜單相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Android編程實(shí)現(xiàn)ActionBar的home圖標(biāo)動(dòng)畫切換效果。分享給大家供大家參考,具體如下:

Material Design中一個(gè)重要特性是側(cè)滑菜單 展開/關(guān)閉 時(shí),ActionBar上的home圖標(biāo)也動(dòng)畫切換。本例要實(shí)現(xiàn)的正是這個(gè)效果,如圖所示:

實(shí)現(xiàn)這個(gè)效果僅需幾步:

1.首先,該頁面的布局是一個(gè)DrawerLayout,代碼如下:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:id="@+id/main_drawer"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <!-- 內(nèi)容布局-->
  <FrameLayout
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />
  <!-- 側(cè)滑菜單-->
  <android.support.design.widget.NavigationView
    android:id="@+id/main_navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/navigation_header"
    app:menu="@menu/menu_drawer" />
</android.support.v4.widget.DrawerLayout>

2.為程序指定Actionbar箭頭按鈕樣式,即如下代碼中的DrawerArrowStyle

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

然后,將AppTheme應(yīng)用到manifest中application標(biāo)簽下。

3. Activity繼承自AppCompatActivity, 然后在onCreate方法中添加代碼(使用Toolbar與此類似):

ActionBar mActionBar = getSupportActionBar();
if (mActionBar != null) {
  mActionBar.setDisplayHomeAsUpEnabled(true);
  mActionBar.setHomeButtonEnabled(true);
}
//實(shí)現(xiàn)左側(cè)home圖標(biāo)“菜單”樣式與“返回”樣式的動(dòng)畫切換(需要在xml中配置相關(guān)樣式)
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.string.drawer_open, R.string.drawer_close);
drawerLayout.setDrawerListener(drawerToggle);

4.在Activity的onPostCreate中添加如下代碼,并且在其它可能需要刷新的地方調(diào)用drawerToggle.syncState() 方法。

@Override
protected void onPostCreate(Bundle savedInstanceState) {
    super.onPostCreate(savedInstanceState);
    drawerToggle.syncState();
}

更多關(guān)于Android相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Android開發(fā)動(dòng)畫技巧匯總》、《Android編程之a(chǎn)ctivity操作技巧總結(jié)》、《Android視圖View技巧總結(jié)》、《Android布局layout技巧總結(jié)》、《Android開發(fā)入門與進(jìn)階教程》、《Android資源操作技巧匯總》及《Android控件用法總結(jié)

希望本文所述對(duì)大家Android程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論