如何扩展操作栏中的导航列表?

发布于 2024-12-28 12:29:52 字数 1045 浏览 5 评论 0原文

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

在此处输入图像描述

我的应用程序:

在此处输入图像描述

这是代码:

//... 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;
    }

}

In android you could set a navigation list in action bar by passing spinner adapter and OnNavigationListener. the issue is that the navigation list dont fill most of the action bar, how to make it expand like the gmail app :
Example of Gmail app :

enter image description here

My app:

enter image description here

And here's the code :

//... 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);

Other problem i face is the size of the spinner item, they show up really small, is that because i dont pass customized textview (look at screenshot)? example of what i do :

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;
    }

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

在梵高的星空下 2025-01-04 12:29:52

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

对于这些情况,请考虑膨胀框架布局 android.R.layout.simple_spinner_itemandroid.R.layout.simple_spinner_dropdown_item。使用 findViewById(android.R.id.text1) 获取您应在每个视图中填写的 TextView

You want to implement the getDropDownView method too. This lets you supply a different view for the dropdown list with the metrics and formatting you want.

Consider inflating the framework layouts android.R.layout.simple_spinner_item and android.R.layout.simple_spinner_dropdown_item for these situations. Use findViewById(android.R.id.text1) to get the TextView you should fill out in each one.

浴红衣 2025-01-04 12:29:52

也许您可以使用 ActionBar 选项卡导航 并将图标添加到选项卡而不是列表导航,因为 gmail 的导航看起来更像选项卡导航。

Maybe you can use ActionBar tab navigation and add icons to the tabs rather than the list navigation since the gmail's navigation looks more like tabs navigation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文