【问题标题】:Sherlock Actionbar custom designSherlock Actionbar 定制设计
【发布时间】:2012-08-09 06:00:11
【问题描述】:

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

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

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

【问题讨论】:

    标签: android android-actionbar actionbarsherlock styling


    【解决方案1】:

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

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

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

    【讨论】:

    • 情况是我需要在我的应用程序中有一个 somekindof 标头,当用户从一个活动导航到另一个活动时,它将保留在它的位置。为此,我已从活动更改为片段。但是第二个麻烦是其中一个片段应该包含一个地图。这就是为什么我需要夏洛克。也许有办法隐藏酒吧?我的“自定义”栏不会留在原地,否则它会在片段过渡时与内容一起滑动?
    • 顺便提醒一下——你需要接受更多的答案。
    • 您可以使用主题设置为您的活动轻松隐藏本机/夏洛克栏: 此外,可以自定义栏通过使用带有栏和片段支架的全局布局文件来保持原位。如果您在片段持有者上进行交易,则该栏会一直存在。但是,根据您在评论中描述的情况,我建议您坚持使用 ActionBarSherlock - 除非您有非常具体的理由不这样做。 Google 试图强制使用严格的导航结构是有原因的:用户熟悉它。
    【解决方案2】:

    是的,您可以像上面显示的那样制作您的 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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-04
      • 1970-01-01
      相关资源
      最近更新 更多