如何在Android Activity中添加工具栏?

7

安卓官方Twitter客户端在点击一条消息时,会出现一个漂亮的工具栏,让您可以进行转发、回复等操作。我该如何重新创建这样的工具栏?


在消息详细视图中显示的工具栏(您截图中的左侧)似乎是一个线性布局,底部排列了一堆按钮。 - aromero
虽然您想要的是QuickAction,但一个可能且简单的解决方案是使用自定义Popupwindow,这也是QuickAction中使用的内容。 - ingsaurabh
2个回答

5
对于LinearLayout方法,代码很简单,只需添加一些权重并调整您想要的内容。这给您提供了该方法的大致思路:
<EditText android:text="Example Layout" 
          android:layout_width="match_parent"
          android:id="@+id/editText"
          android:layout_height="wrap_content"
          android:layout_weight="0.95"></EditText>

<LinearLayout
  android:layout_width="fill_parent"
  android:orientation="horizontal"
  android:weightSum="1.0" 
  android:padding="1px"
  android:layout_height="wrap_content"
  android:layout_weight="0.05">

  <ImageButton android:id="@+id/testButton1"
          android:layout_weight="0.2"
          android:background="@drawable/btn"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content"/>

  <ImageButton android:id="@+id/testButton2"
          android:layout_weight="0.2"
          android:background="@drawable/btn"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content" />

  <ImageButton android:id="@+id/testButton3"
          android:layout_weight="0.2"
          android:background="@drawable/btn"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content" />

  <ImageButton android:id="@+id/testButton4"
          android:layout_weight="0.2"
          android:background="@drawable/btn"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content" />

  <ImageButton android:id="@+id/testButton5"
          android:layout_weight="0.2"
          android:background="@drawable/btn"
          android:layout_height="wrap_content"
          android:layout_width="wrap_content" />

</LinearLayout>

而且结果像这样:http://i.stack.imgur.com/bShgb.png

您也可以使用ActionBar,只需注意API要求:http://developer.android.com/guide/topics/ui/actionbar.html


1
他知道什么是工具栏以及它的作用,他正在寻求一种实现方式。顺便提一下,http://www.androidpatterns.com/uap_pattern/toolbar。 - aromero
这是Twitter工具栏的屏幕截图 http://www.wirefresh.com/images/twitter-android-update-1.jpg - Sheehan Alam
我知道至少有两种不同的工具栏视图,所以感谢您提供的截图。您尝试过在水平LinearLayout中放置按钮吗? - Jack

3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接