0

如果有人能帮我找出一些关于自定义 sherlock 操作栏的细节,我将非常感激。

更具体地说:我需要一个带有四个按钮的操作栏。栏两侧的两个小按钮(左侧和右侧的第二个),栏中间的一个“配对”单选按钮。当我说“配对”时,我的意思是在 iOS 中,当有两个按钮彼此靠近时,当我按下一个时 - 第二个未按下,反之亦然。总而言之,它应该看起来像这样。

理论动作条夏洛克

是否有可能做到这一点,或者我应该忘记使用美妙的夏洛克生物?

4

2 回答 2

6

我个人会放弃使用 ActionBarSherlock 的想法,而是使用您自己的布局资源来实现它。

作为 ActionBarSherlock 的用户,我可以说它是一个很棒的库,因为它本质上允许您在所有设备上使用 ActionBar API,包括 pre-Honeycomb,这意味着您不必编写单独的 UI 来适应 pre-Honeycomb 设备。但是ActionBarSherlock 的重点在于它只是提供了与原生ActionBar 等效的API。问题在于,ActionBar 限制了您可以创造性地使用它做什么,因为它旨在提供特定的功能和控件,这些功能和控件符合 Google 希望您实现 UI 的方式。简而言之,您可以指定自定义布局View出现在栏内的某处。您还可以控制哪些菜单项显示为放置在栏右侧的操作项(但最终仍取决于系统,基于屏幕空间,如果此类项目在栏上可见)。该栏还允许您实现一些非常特殊的功能(Action Views、Action Providers 等)

但是,如果您希望创建一个非常自定义的布局,就像您所描绘的那样,并且您不需要 ActionBar(或 ActionBarSherlock)提供的特殊功能,那么您最好从头开始做。

于 2012-08-09T06:16:21.503 回答
0

是的,您可以像上面显示的那样制作您的 Sherlock 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>
于 2013-02-15T08:18:34.310 回答