样式.xml
<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
<item name="android:homeAsUpIndicator">@drawable/ic_back</item>
<item name="homeAsUpIndicator">@drawable/ic_back</item>
</style>
主 Activity .java
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP);
actionBar.setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
View actionBarView = inflator.inflate(R.layout.custom_title, null);
actionBar.setCustomView(actionBarView);
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.drawable.ic_action_nav_menu, //nav menu toggle icon
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
) {
public void onDrawerClosed(View view) {
tvTitle.setText(mTitle);
//getActionBar().setTitle(mTitle);
// calling onPrepareOptionsMenu() to show action bar icons
invalidateOptionsMenu();
}
public void onDrawerOpened(View drawerView) {
tvTitle.setText(mDrawerTitle);
//getActionBar().setTitle(mDrawerTitle);
// calling onPrepareOptionsMenu() to hide action bar icons
invalidateOptionsMenu();
}
};
你可以在上图中看到,我想在黑色圆圈中显示 3 行图像而不是背面符号图像。
最佳答案
使用 android.support.v7 而不是 android.support.v4 如下:
import android.support.v7.app.ActionBarDrawerToggle;
并将您的 mDrawerToggle 更改为以下内容:
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
R.string.app_name, // nav drawer open - description for accessibility
R.string.app_name // nav drawer close - description for accessibility
)...
添加以下代码:
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
// Defer code dependent on restoration of previous instance state.
mDrawerLayout.post(new Runnable() {
@Override
public void run() {
mDrawerToggle.syncState();
}
});
关于android - 使用 appcompat v7 不显示抽屉导航图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30740055/