在屏幕底部创建选项菜单,没有操作栏

时间:2015-02-13 05:12:21

标签: android android-optionsmenu

我已经看过类似的问题,但大多数解决方案都围绕着一个分裂的动作栏。我不认为这可以在我的应用中使用,因为我的主题是Theme.Material.Light.NoActionBar

Here是我想做的一个例子。溢出菜单位于右下角,点击后,ListView会打开,类似于常规选项菜单example seen here

我不确定是否可以使用onCreateOptionsMenuonOptionsItemSelected等原生函数。我怎么能绕过没有动作栏?嵌套片段会起作用吗?

我的应用布局是ViewPager内的片段。我的溢出菜单按钮的代码很简单,但我不知道如何在ListView方法中打开onClick

mSettingsButton = (Button) findViewById(R.id.settingsButton);
mSettingsButton.setOnClickListener(new View.OnClickListener()
{
    @Override
    public void onClick(View v)
    {

    }
});

我很感激任何建议或例子。谢谢!

2 个答案:

答案 0 :(得分:2)

你可以在屏幕上使用Toolbar类和样式/定位它。

例如

<android.support.v7.widget.Toolbar
android:id=”@+id/my_awesome_toolbar”
android:layout_height=”wrap_content”
android:layout_width=”match_parent”
android:minHeight=”?attr/actionBarSize”
android:background=”?attr/colorPrimary” />

之后,使用

Toolbar toolbar = (Toolbar) findViewById(R.id.my_awesome_toolbar);
setSupportActionBar(toolbar);

将其设置为主操作栏。 onCreateOptionsMenu和其他与操作栏相关的功能将按预期工作。确保您也禁用主题中的默认操作栏。

答案 1 :(得分:1)

您可以通过按钮

使用ListPopupWindow进行ListView

例如:

ListPopupWindow popup = new ListPopupWindow(SomeActivity.this);
popup.setAdapter(new ArrayAdapter(SomeActivity.this,R.layout.list_item, someSettings));
popup.setAnchorView(settingsButton);
popup.setWidth(300);
popup.setHeight(400);

popup.setModal(true);
popup.setOnItemClickListener(SomeActivity.this);
settingsButton.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        popup.show();
    }
});
相关问题