我有一个关于我的
ActionBar
的问题,导致我的菜单图标紧贴着屏幕边缘被压缩了!
以下是我调整的风格和声明的一些代码片段:
HomeActivity.xml
private TextView tvViewAll;
DrawerLayout mDrawerLayout;
private ActionBarDrawerToggle mDrawerToggle;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
//Nav Drawer
mDrawerLayout = findViewById(R.id.drawer_layout);
//custom shadow for menu drawer
mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
// ActionBarDrawerToggle ties together the the proper interactions
// between the sliding drawer and the action bar app icon
mDrawerToggle = new ActionBarDrawerToggle (this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);
mDrawerLayout.addDrawerListener(mDrawerToggle);
mDrawerToggle.syncState();
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(mDrawerToggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:statusBarColor">@color/colorBackgroundBlack</item>
<item name="android:navigationBarColor">@color/colorBackgroundBlack</item>
<item name="actionMenuTextColor">@color/colorBackgroundBlackDark</item>
<item name="colorPrimary">@color/colorBackgroundBlackDark</item>
<item name="colorAccent">@color/colorPrimaryDark</item>
<item name="colorButtonNormal">@color/ipBlue</item>
<item name="toolbarNavigationButtonStyle">@color/ipGreen</item>
</style>
<style name="ActionBar.Solid.TMSA.NoTitle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="displayOptions">useLogo|showHome</item>
<item name="logo">@drawable/ic_ipaustralialogo</item>
<item name="android:contentDescription">@string/ip_logo</item>
</style>
<style name="AppTheme.TMSA" parent="@style/AppTheme">
<item name="actionBarStyle">@style/ActionBar.Solid.TMSA.NoTitle</item>
</style>
我不记得除了包含政府标志外,我有没有更改过 ActionBar
的格式布局,但我无法想出为什么我会得到这个歪斜的菜单图标。
我已经考虑过使用 Toolbar
方法,但不想进行转换:P
编码愉快 :)
toolbarNavigationButtonStyle
不仅需要颜色,还需要样式。我猜测它失败了;至少,默认样式中设置的最小宽度值没有被获取到。如果你想修改该样式,应该创建一个以默认样式为父级的自定义样式,并在其中设置所需属性;可以参考此答案中的第一个代码块。 - Mike M.