简体   繁体   中英

How to add a toolbar to an Android Activity?

当您单击允许转推,回复等的消息时,Android的官方Twitter客户端有一个很好的工具栏。如何重新创建这样的工具栏?

For the LinearLayout approach, the code is simple, just add some weights and play around with what your looking for. This gives you a rough idea of the approach:

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

And results in something like this: http://i.stack.imgur.com/bShgb.png

You may also be happy with ActionBar as well, just watch the API requirements: http://developer.android.com/guide/topics/ui/actionbar.html

We call it QuickAction:

在此输入图像描述在此输入图像描述

Find more about how to implement it here: http://www.londatiga.net/it/how-to-create-quickaction-dialog-in-android/

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