【问题标题】:How to make the navigation icon open a dropdown menu onclick? (Android)如何使导航图标在单击时打开下拉菜单? (安卓)
【发布时间】:2019-06-18 14:39:23
【问题描述】:

所以,我知道这可能是一个非常简单的问题,但是我发现问题的解决方案非常丑陋,因此我转向你。

我有一个如下的操作栏:

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize">

    <com.google.android.material.appbar.MaterialToolbar
        android:id="@+id/toolbar"
        style="@style/Widget.AppCompat.Toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:title="@string/app_name"
        app:navigationIcon="@drawable/ic_menu_black_24dp">

    </com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>

我根本找不到任何正常的方式导致三明治图标在被点击后打开一个小的选项下拉菜单。

感谢帮助者!

【问题讨论】:

    标签: android android-layout android-actionbar onclicklistener android-drawable


    【解决方案1】:

    您需要在活动类文件中为此添加菜单代码,

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Get menu inflater.
        MenuInflater menuInflater = getMenuInflater();
    
        // Use app bar layout menu to inflate the tool bar.
        menuInflater.inflate(R.menu.your_menu_name, menu);
        return super.onCreateOptionsMenu(menu);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 1970-01-01
      相关资源
      最近更新 更多