简体   繁体   中英

Sherlock Actionbar custom design

I will be very thankfull if anyone will help me find out some details about customizing sherlock actionbar.

To be more concrete: I need an action bar with four buttons. Two small buttons on the sides of the bar (on on the left side and second on the right), and one "paired" radiobutton in the middle of the bar. When I say "paired" I mean something like in iOS when there are two buttons positioned near each other and when I press one - the second is unpressed and vice versa. All in all it should look like this.

伸缩动作条夏洛克

Is it even possible to make this or I should forget about using the wonderful sherlock creature?

I would personally abandon the idea of using ActionBarSherlock and instead just implement this using your own layout resource.

As a user of ActionBarSherlock I can say it's a fantastic library, as it essentially allows you to use the ActionBar API across all devices, including pre-Honeycomb, meaning you don't have to code a separate UI to suit pre-Honeycomb device. But the point of ActionBarSherlock is that it just provides APIs that are equivalent to those of the native ActionBar. And the problem is that the ActionBar is restrictive in what you can creatively do with it, because it is designed to offer specific functionality and controls that kind of fit around how Google want you to implement your UI. In a nutshell, you can specify a custom layout View that appears somewhere within the bar. You can also control which menu items appear as action items placed on the right-hand side of the bar (though it is ultimately still up to the system, based on screen space, if such items are made visible on the bar). The bar also allows you to implement some very special functionality (Action Views, Action Providers, etc.)

But if you're looking to create a very customised layout like the one you've pictured, and you don't need the special functionality that the ActionBar (or ActionBarSherlock) provides, then you might be better off doing it from scratch.

Yes you can make your Sherlock ActionBar like you show above. you have to set custom View to your SherLock ActionBAr. Just few lines of code

   getSupportActionBar()
            .setDisplayShowCustomEnabled(true);
   getSupportActionBar().setCustomView(
            R.layout.your_custom_layout);

and you custom layout should be RelativeLayout something like this

    <?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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM