java - 如何用图像按钮替换设置项

标签 java android android-actionbar

我正在android studio中开发一个抽屉导航 Activity ,在菜单文件夹的左上角有一个设置项。我想删除它并在操作栏中添加一个图像按钮。谁能告诉我如何添加该图像按钮以及如何在主 Activity 中对该按钮执行单击事件。

查看下面的图片以供引用 -

enter image description here

最佳答案

我希望这有帮助,请将其添加到您的 menu.xml 布局中 -

The showAsAction attribute allows you to define how the action is displayed. For example, the ifRoom attribute defines that the action is only displayed in the action bar if there is sufficient screen space available.

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:icon="@drawable/ic_settings"
        android:title="Settings">
    </item>

</menu>

关于java - 如何用图像按钮替换设置项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46192191/

相关文章:

java - 在我的主程序上传递字符串/路径参数以打开图像文件

java - NullPointerException 致命异常 : Thread-5023 error

android - 为 ListView 设置选择器时出现异常

android - 通过上下文操作栏获取 WebView 中的选定文本

android - Xamarin Android - 操作栏图标填充

java - 将字符串从 Java 发送到 C(套接字)

java - 如何将字符串(长度为1)转换为相关的ASCII码(0-255)的int值?

java - 如何克服这个强制转换异常?

android - 如何获取光传感器值

android - 用于手动实现的 ActionBar 溢出菜单样式信息