如何将工具栏添加到Android Activity?

She*_*lam 7 java eclipse android adt

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

Jac*_*ack 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>
Run Code Online (Sandbox Code Playgroud)

结果如下:http: //i.stack.imgur.com/bShgb.png

您也可以对ActionBar感到满意,只需观看API要求:http: //developer.android.com/guide/topics/ui/actionbar.html