在 android 中,您可以通过传递微调器适配器和 OnNavigationListener 在操作栏中设置导航列表。问题是导航列表没有填充大部分操作栏,如何使其像 gmail 应用程序一样展开:Gmail 应用程序示例:

enter image description here

我的应用程序:

enter image description here

这是代码:

//... setting the array adapter
ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
NavigationListener navigationListener = new NavigationListener();
ListAdapter listAdapter = new ListAdapter();
actionBar.setListNavigationCallbacks(listAdapter, navigationListener);
actionBar.setDisplayShowTitleEnabled(false);

我面临的其他问题是旋转项目的大小,它们显示得非常小,是因为我没有传递自定义文本视图(看屏幕截图)吗?我所做的例子:

private class ListAdapter extends BaseAdapter implements SpinnerAdapter {

    public View getView(int pos, View view, ViewGroup viewGroup) {
        TextView text = new TextView(context);
        text.setText(arrayAdapter.getItem(pos).toString());
        return text;
    }

}
有帮助吗?

解决方案

您想要实施 getDropDownView 方法也。这使您可以为下拉列表提供不同的视图,并包含所需的指标和格式。

考虑扩大框架布局 android.R.layout.simple_spinner_itemandroid.R.layout.simple_spinner_dropdown_item 对于这些情况。使用 findViewById(android.R.id.text1) 得到 TextView 您应该填写每一项。

其他提示

也许你可以使用动作栏选项卡导航并将图标添加到选项卡而不是列表导航,因为Gmail的导航更像是标签导航。
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top