我有一个动作sherlock栏,我需要自定义此控件如下图所示.我需要一个伪代码或类似的简单例子.我下载了库,示例,我一直在这个网站和谷歌搜索,但我找不到这样的东西.
很抱歉,如果信息不完整,那么我会根据您需要的信息编辑帖子.谢谢.
很抱歉,如果信息不完整,那么我会根据您需要的信息编辑帖子.谢谢.
注意:
>我不想使用android.support.v4.widget.DrawerLayout,ActionBarDrawerToggle.我需要sherlock滑动效果.
>我需要在菜单选项列表(LISTVIEW)上方添加图像和标签(参见右图).
将来我需要一个像下面这样的栏(样式必须类似于see this link)
解决方法
SidingMenu布局:
您应该将ListView设置为菜单布局.接下来,使用ImageView和TextView创建sliding_menu_header.xml布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<ImageView
android:src="@drawable/image_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:text="text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
现在,您可以膨胀此布局并将其设置为ListView的标题视图:
View menuHeader = getLayoutInflater().inflate(R.layout.sliding_menu_header,null); mListView.addHeaderView(menuHeader); mListView.setAdapter(mYourMenuAdapter);
ActionBar布局:
您可以向ActionBar添加自定义视图.在您的情况下,布局可以是:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/button1"
android:text="button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/button2"
android:text="button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
然后在onCreate方法中添加以下行:
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.actionbar_view);
actionBar.setdisplayOptions(ActionBar.disPLAY_SHOW_CUSTOM
| ActionBar.disPLAY_SHOW_HOME);
Button button1 = actionBar.getCustomView.findViewById(R.id.button1);
Button button2 = actionBar.getCustomView.findViewById(R.id.button2);
希望它对你有所帮助.如果我的答案不完整请评论,我会更新.