[英]Change Action Bar Overflow Icon in an app
I am trying to change the Action Bar Overflow Icon in an app. 我正在尝试在应用程序中更改操作栏溢出图标。 I have seen some info on this site but it's not clear to me. 我已经在该网站上看到了一些信息,但我不清楚。 Does anyone know what code I should enter and in what files? 有人知道我应该输入什么代码以及在什么文件中吗?
Try this may be helpful to you 试试这个可能对您有帮助
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setIcon(R.mipmap.ic_title);
......
}
You can change the Overflow Icon
programmatically by using Toolbar.setOverflowIcon()
method. 您可以使用Toolbar.setOverflowIcon()
方法以编程方式更改“ Overflow Icon
。
// ToolBar
Toobar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
toolbar.setOverflowIcon(getResources().getDrawable(R.drawable.your_overflow_icon));
}
Toolbar XML 工具栏XML
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:minHeight="?attr/actionBarSize"
app:theme="@style/ThemeOverlay.AppCompat.Light"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
</android.support.v7.widget.Toolbar>
or, you can also define a style
for custom Overflow Icon
in your main styles.xml
like this: 或者,您也可以在主styles.xml
为自定义“ Overflow Icon
定义style
,如下所示:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light">
<item name="actionOverflowButtonStyle">@style/OverFlow</item>
</style>
<style name="OverFlow" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/your_overflow_icon</item>
</style>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.