我想在操作栏中设置自定义汉堡按钮( ic_navigation_drawer ):
我的自定义主题:
<!-- Base application theme. -->
<style name="MainAppBaseTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/DefaultActionBar</item>
</style>
<style name="CustomActionBarTheme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:actionBarStyle">@style/DefaultActionBar</item>
</style>
<!-- Default actionBar styles -->
<style name="DefaultActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid.Inverse">
<item name="android:background">@color/colorPrimary</item>
<item name="android:titleTextStyle">@style/DefaultActionBar.TitleTextStyle</item>
</style>
在manifest.xml中
<application
android:name=".main.MainApp"
android:allowBackup="true"
android:icon="@drawable/ic_app"
android:label="@string/application_name"
android:logo="@drawable/ic_app_logo"
android:theme="@style/MainAppBaseTheme">
在我的androidx.fragment.app.FragmentActivity中:
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout;
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setHomeAsUpIndicator(R.drawable.ic_navigation_drawer);
mToolbar = (Toolbar) findViewById(R.id.toolBar);
actionBarDrawerToggle = new ActionBarDrawerToggle(
this,
mDrawerLayout,
mToolbar, R.string.application_name,
R.string.application_name) {
public void onDrawerClosed(View view) {
mToolbar.setTitle(mTitle);
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
mToolbar.setTitle(mDrawerTitle);
invalidateOptionsMenu();
loadDraftsTotalNumber();
loadActiveCart();
}
};
mDrawerLayout.setDrawerListener(actionBarDrawerToggle);
@Override
protected void onPostCreate(Bundle savedInstanceState) {
if (BuildConfig.DEBUG)
Log.d(TAG, "onPostCreate");
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
actionBarDrawerToggle.syncState();
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
// Pass any configuration change to the drawer toggles
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
这里是结果
如您所见,导航按钮(汉堡)未更改。同样,在打开/关闭导航抽屉时它没有动画
为什么?