如何扩展操作栏中的导航列表?
在 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 :
My app:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您想要实现
getDropDownView
方法也是如此。这使您可以为下拉列表提供不同的视图,并包含所需的指标和格式。对于这些情况,请考虑膨胀框架布局
android.R.layout.simple_spinner_item
和android.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
andandroid.R.layout.simple_spinner_dropdown_item
for these situations. UsefindViewById(android.R.id.text1)
to get theTextView
you should fill out in each one.也许您可以使用 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.