Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a toolbar to an Android Activity?

The official Twitter client for Android has a nice toolbar when you click on a message that lets you retweet, reply, etc. How can I re-create a toolbar like that?

like image 590
Sheehan Alam Avatar asked Apr 26 '11 02:04

Sheehan Alam


People also ask

Where is a toolbar placed in the activity?

In Android applications, Toolbar is a kind of ViewGroup that can be placed in the XML layouts of an activity.

How do I show the toolbar on Android?

You can similarity assign to Main Menu-> View-> Toolbar and show toolbar again on Android studio IDE. Alternatively, after the main menu opened, click VIEW-> Toolbar tab. Save this answer. Show activity on this post.

What is the difference between a toolbar and an action bar?

What is the difference between the toolbar and the action bar? The most obvious difference between the two is the updated visual design of the toolbar. The toolbar no longer includes an icon on the left side and decreases some of the spacing between the action items on the right side.


2 Answers

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

like image 60
Jack Avatar answered Sep 27 '22 17:09

Jack


We call it QuickAction:

enter image description hereenter image description here

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

like image 34
anticafe Avatar answered Sep 27 '22 16:09

anticafe