【发布时间】:2017-11-06 05:25:08
【问题描述】:
我的ActionBar 有问题,导致我的菜单图标被按到屏幕边缘!
下面是我调整的样式和声明的一些代码 sn-ps:
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>
除了包含 gov 徽标之外,我不记得触摸过 ActionBar 的格式布局,但我无法弄清楚为什么会出现这个歪斜的菜单图标。
我已经考虑过使用Toolbar 方法,但不希望必须转换:P
编码愉快:)
【问题讨论】:
-
toolbarNavigationButtonStyle采用一种风格,而不仅仅是一种颜色。我猜想它失败了。至少,它没有获得默认样式中设置的最小宽度值。如果要修改该样式,则应创建自己的样式,并将默认样式作为父样式,并在其中设置所需的属性; this answer 的第一个代码块中显示了类似的内容。 -
没问题。顺便说一句,我不确定您要在哪个部分上色,但是动画汉堡箭头可绘制对象有自己的样式,您也可以修改。 this answer 中有一个例子。
-
@MikeM。即使没有调整汉堡包/箭头!我会试一试:)也 - 很抱歉打扰你,但我试图将你的第一条评论标记为正确答案,但我什至不能投票给你 - 是因为我是新手还是..?
-
是的,我认为在达到 15 个代表之前你不能投票。此外,您不能将评论标记为答案。不过,给我一点,我会在下面整理一个实际答案,你可以用复选标记接受。如果这确实是您要修改的内容,我将包含您可以在可绘制对象上设置的属性列表。很高兴你修好了它。干杯!
标签: java android menu android-actionbar icons