2011-04-26 74 views
7

Android的官方Twitter客戶端有一個不錯的工具欄,當你點擊一條消息,可以讓你轉推,回覆等。我該如何重新創建一個工具欄?如何將工具欄添加到Android活動?

+0

是在消息的詳細視圖(一個在左在你的屏幕截圖)顯示的工具欄似乎是一個一個的LinearLayout屏幕底部佈滿了一堆按鈕。 – aromero 2011-04-26 02:36:27

+0

雖然你想要的是QuickAction,但一個可能的和簡單的解決方案是使用QuickAction中使用的自定義Popupwindow – ingsaurabh 2011-04-26 04:45:34

回答

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

你也可以很樂意與動作條爲好,只是看API要求:http://developer.android.com/guide/topics/ui/actionbar.html

+1

他知道什麼是工具欄,什麼是他要求的實現。順便說一句http://www.androidpatterns.com/uap_pattern/toolbar – aromero 2011-04-26 02:21:47

+0

這裏是Twitter工具欄的屏幕截圖http://www.wirefresh.com/images/twitter-android-update-1.jpg – 2011-04-26 02:23:34

+0

至少有2個不同的我知道的工具欄的意見,所以謝謝你的截圖。你有沒有試過一個簡單的水平LinearLayout放置它的按鈕? – Jack 2011-04-26 02:37:56