Gas*_*res 7 android actionbarsherlock android-actionbar
我有一个动作sherlock栏,我需要自定义此控件如下图所示.我需要一个伪代码或类似的简单例子.我下载了库,示例,我一直在这个网站和谷歌搜索,但我找不到这样的东西.很抱歉,如果信息不完整,那么我会根据您需要的信息编辑帖子.谢谢.
注意:

将来我需要一个像下面这样的栏(样式必须类似于看到此链接)

SidingMenu布局:
您应该设置ListView为菜单布局.接下来,sliding_menu_header.xml使用ImageView和TextView内部创建布局:
<?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>
Run Code Online (Sandbox Code Playgroud)
现在,您可以膨胀此布局并将其设置为ListView标题视图:
View menuHeader = getLayoutInflater().inflate(R.layout.sliding_menu_header, null);
mListView.addHeaderView(menuHeader);
mListView.setAdapter(mYourMenuAdapter);
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
然后在您的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);
Run Code Online (Sandbox Code Playgroud)
希望它对你有所帮助.如果我的答案不完整请评论,我会更新.
实现“滑动菜单”,与 Sherlock ActionBar 完美搭配
链接库
https://github.com/jfeinstein10/SlidingMenu
实现两个库的视频教程
https://www.youtube.com/watch?v=IW6idyV0CZQ
编辑
//pre-ICS
if (actionBarSherlock instanceof ActionBarImpl) {
enableEmbeddedTabs(actionBarSherlock);
//ICS and forward
} else if (actionBarSherlock instanceof ActionBarWrapper) {
try {
Field actionBarField = actionBarSherlock.getClass().getDeclaredField("mActionBar");
actionBarField.setAccessible(true);
enableEmbeddedTabs(actionBarField.get(actionBarSherlock));
} catch (Exception e) {
Log.e(TAG, "Error enabling embedded tabs", e);
}
}
//helper method
private void enableEmbeddedTabs(Object actionBar) {
try {
Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod("setHasEmbeddedTabs", boolean.class);
setHasEmbeddedTabsMethod.setAccessible(true);
setHasEmbeddedTabsMethod.invoke(actionBar, true);
} catch (Exception e) {
Log.e(TAG, "Error marking actionbar embedded", e);
}
}
Run Code Online (Sandbox Code Playgroud)
看那个链接:
https://groups.google.com/forum/#!topic/actionbarsherlock/hmmB1JqDeCk
当操作栏上有选项卡时,您可以为选项卡、边框、背景图像、重力设置一种样式,并提供按钮外观。
看:
http://www.silverbaytech.com/2013/05/13/themes-for-the-android-actionbar-tabs/
尝试一下并告诉我们。
| 归档时间: |
|
| 查看次数: |
1360 次 |
| 最近记录: |