如果有人能帮我找出一些关于自定义神探动作栏的细节,我将非常感谢。
更具体地说:我需要一个有四个按钮的操作栏。栏两侧的两个小按钮(左侧打开,右侧第二个),以及栏中间的一个“配对”单选按钮。当我说“配对”时,我指的是在iOS中,当有两个按钮彼此靠近时,当我按下一个按钮时,第二个按钮是未按下的,反之亦然。总而言之,它应该是这样的。
有没有可能做到这一点,或者我应该忘记使用神奇的神探夏洛克生物?
发布于 2012-08-09 14:16:22
我个人会放弃使用ActionBarSherlock的想法,而只是使用你自己的布局资源来实现它。
作为ActionBarSherlock的用户,我可以说它是一个很棒的库,因为它基本上允许你在所有设备上使用ActionBar应用程序接口,包括蜂巢之前的设备,这意味着你不必编写单独的UI来适应蜂巢之前的设备。但ActionBarSherlock的要点在于,它只提供与原生ActionBar等效的API。问题是,ActionBar限制了你对它的创造性操作,因为它的设计是为了提供特定的功能和控件,这些功能和控件与谷歌希望你实现UI的方式相吻合。简而言之,您可以指定一个显示在栏中某处的自定义布局View
。您还可以控制哪些菜单项显示为放置在栏右侧的操作项(不过,如果这些菜单项在栏上可见,则最终仍取决于系统,具体取决于屏幕空间)。工具栏还允许您实现一些非常特殊的功能(操作视图、操作提供程序等)。
但是,如果您希望创建一个非常定制的布局,并且不需要ActionBar (或ActionBarSherlock)提供的特殊功能,那么从头开始可能会更好。
发布于 2013-02-15 16:18:34
是的,你可以制作你的神探夏洛克ActionBar,就像你上面展示的那样。您必须为您的SherLock ActionBAr设置自定义视图。只有几行代码
getSupportActionBar()
.setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(
R.layout.your_custom_layout);
您的自定义布局应该是RelativeLayout,如下所示
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="72dp" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:src="@drawable/icon" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" >
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/icon" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:src="@drawable/icon" />
</LinearLayout>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:src="@drawable/icon" />
</RelativeLayout>
https://stackoverflow.com/questions/11877544
复制相似问题