【问题标题】:How to remove three dots from the toolbar of navigation drawer如何从导航抽屉的工具栏中删除三个点
【发布时间】:2017-10-29 06:51:39
【问题描述】:

我想从工具栏中删除这 3 个点,还想在该位置添加一个带有 textview 的图像。每个片段活动的图像和 textview 都不同。

还有谁能告诉我如何使工具栏透明。

【问题讨论】:

标签: android android-fragments material-design navigation-drawer


【解决方案1】:

在您的 MainActivity 中,您将拥有选项菜单,只需将其设为 false

 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
       return false;
 }

【讨论】:

  • 但是我怎样才能在那个地方添加图像视图和文本视图呢?
  • 自定义工具栏。
  • 如何创建自定义工具栏?不要介意我的愚蠢问题,我只是一个初学者
  • 这会帮助你google.co.in/…
【解决方案2】:

1)您关于删除三个点的第一个问题(Aditya -Vyas)解决了您的问题

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
       return false;
 }

2) 现在放置图像视图 板条箱菜单资源

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

    <item
        android:id="@+id/action_submit"
        android:title="@string/submit"
        android:icon="@drawable/ask_price_back"
        app:showAsAction="always" />
</menu>

然后声明 onCrateOptionsMenu 和 onOptionsImtemSelected 如下

  @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_submit, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_submit) {

            //Your code to handle click 

            return true;
        }
        return super.onOptionsItemSelected(item);
    }

3) 处理Activity中加载的片段中的菜单试试这个

在您的片段中覆盖此方法

@Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        getActivity().getMenuInflater().inflate(R.menu.menu_of_fragment, menu);
    }

     @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        if (id == R.id.action_fragment) {

            // Your code to handle Click
        }

        return super.onOptionsItemSelected(item);
    }

【讨论】:

  • 先生,我已经分享了我的代码,你给了我答案。请参阅stackoverflow.com/questions/44197429/…
  • 所以你必须从片段仪式中调用菜单?
  • @Anu 你创建了我提到的菜单资源文件吗?
  • 是的,先生。我做到了。我在 main.xml 文件中添加了这些项目。我还对 MainActivity 中的 onCreateOptionsMenu 和 onOptionsItemSelected 方法进行了更改。一切都好吗?
  • 图像正在显示 :) 但我需要从片段活动中设置它。
【解决方案3】:

1) 从您的 menu.xml 中删除所有带有标签的项目。 这将从您的菜单区域中删除三个点。

2) 在你的 xml 中添加一个新项目并给出属性

android:icon="@drawable/image_you_want to show in the menu area"
app:showAsAction="always"

【讨论】:

    【解决方案4】:

    设置你的风格

       <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
        <item name="android:actionOverflowButtonStyle">@style/MyActionButtonOverflow</item>
    </style>
    
    <!-- Style to replace actionbar overflow icon. set item 'android:actionOverflowButtonStyle' in AppTheme -->
    <style name="MyActionButtonOverflow" parent="android:style/Widget.Holo.Light.ActionButton.Overflow">
        <item name="android:src">@drawable/ic_launcher</item>
    </style>
    

    查看此帖子:post

    【讨论】:

    • 感谢您的回复
    • 欢迎您,如果它对您有用,请接受答案,谢谢。
    • 这不是用于工具栏的...这是用于操作栏的
    【解决方案5】:
        > for adding imageview and text
    
    
        ` <item android:id="@+id/action_cart"
                android:icon="@drawable/cart2"
                android:title="image"
                app:showAsAction="always"  />
    
            <item
                android:id="@+id/badge"
                app:actionLayout="@layout/counter"
                android:title="image"
                android:icon="@drawable/shape"
                app:showAsAction="always">
            </item>`
    
      In Layout counter
    `<TextView
            android:id="@+id/notif_count"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:minWidth="20dp"
            android:minHeight="20dp"
            android:background="@drawable/shape"
            android:text="0"
            android:textSize="14sp"
            android:textColor="#fff"
            android:gravity="center"
            android:padding="2dp"
            android:singleLine="true">
        </TextView>`
    

    【讨论】:

    • 在布局计数器中
    【解决方案6】:

    从菜单中删除此项。

    <item
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        android:showAsAction="never"
        visibility=false
        android:title="@string/action_settings"/>
    

    【讨论】:

    • 或设置 visibilty=false
    猜你喜欢
    • 1970-01-01
    • 2019-09-15
    • 2014-12-23
    • 2015-02-26
    • 2015-01-15
    • 2016-03-26
    • 2021-05-12
    • 1970-01-01
    相关资源
    最近更新 更多