Action Bar

Quickly share your Android Code Snippets here...

Action Bar

Postby izu516 » Tue Aug 17, 2010 4:12 pm

While this may be relatively simple, hopefully this will save time instead of reinventing the wheel!

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.         android:orientation="horizontal" android:layout_width="fill_parent"
  4.         android:layout_height="50dip" android:background="#ffbbbbbb">
  5.         <TextView android:layout_width="wrap_content" android:layout_centerVertical="true"
  6.                 android:textColor="@color/white" android:textSize="7pt"
  7.                 android:textStyle="bold" android:layout_height="wrap_content"
  8.                 android:text="My App" android:padding="8dp" />
  9.  
  10.         <ImageView android:layout_width="1px" android:src="#ffffffff"
  11.                 android:layout_height="wrap_content" android:text="@string/hello"
  12.                 android:id="@+id/bordertwo" android:layout_toLeftOf="@+id/refresh"
  13.                 android:layout_marginRight="12dip" android:layout_alignParentBottom="true"
  14.                 android:layout_alignParentTop="true" />
  15.  
  16.         <ImageView android:layout_width="25dip" android:src="@drawable/title_refresh"
  17.                 android:layout_height="25dip" android:text="@string/hello"
  18.                 android:layout_marginRight="12dip" android:layout_centerVertical="true"
  19.                 android:id="@+id/refresh" android:layout_toLeftOf="@+id/borderone"
  20.                 android:scaleType="fitXY" />
  21.  
  22.         <ImageView android:layout_width="wrap_content" android:src="#ffffffff" android:layout_height="wrap_content"
  23.                 android:id="@+id/borderone" android:layout_alignParentTop="true"
  24.                 android:layout_marginRight="12dip" android:layout_alignParentBottom="true"
  25.                 android:layout_alignBottom="@+id/search" android:text="@string/hello"
  26.                 android:layout_toLeftOf="@+id/search" />
  27.  
  28.         <ImageView android:src="@drawable/title_search" android:text="@string/hello"
  29.                 android:layout_width="25dip" android:layout_alignParentRight="true"
  30.                 android:layout_centerVertical="true" android:id="@+id/search"
  31.                 android:layout_marginRight="12dip" android:layout_height="25dip"
  32.                 android:scaleType="fitXY" />
  33. </RelativeLayout>
  34.  
  35.  
Parsed in 0.007 seconds, using GeSHi 1.0.8.4


Great for mdpi and hdpi displays, might need just a little touch for ldpi, though. Included are the referenced images and their focused alternatives (not the XML drawables though, but it shouldn't be very difficult). The images I've included are: search, home, export, map, refresh, and share. Hope you find this useful :D
Attachments
ActionBarIcons.zip
Action Bar Icons
(8.49 KiB) Downloaded 865 times
screeshot.png
Screenshot
screeshot.png (11.15 KiB) Viewed 6190 times
Go anddev!
izu516
Developer
Developer
 
Posts: 27
Joined: Sat Nov 14, 2009 2:18 am
Location: US

Top

Re: Action Bar

Postby huangcanxian » Thu Aug 26, 2010 10:57 am

Good ,thank you very much!!!!!!!
huangcanxian
Once Poster
Once Poster
 
Posts: 1
Joined: Mon Aug 02, 2010 3:26 pm

Re: Action Bar

Postby jdot » Wed Nov 10, 2010 1:56 pm

Thanks a lot ! Are the Icons available for free by any chance ?
jdot
Freshman
Freshman
 
Posts: 5
Joined: Wed Sep 29, 2010 8:37 am

Re: Action Bar

Postby izu516 » Wed Nov 10, 2010 8:51 pm

Of course. They're extracted from the Google IO app (the code I made myself, though).
Go anddev!
izu516
Developer
Developer
 
Posts: 27
Joined: Sat Nov 14, 2009 2:18 am
Location: US

Re: Action Bar

Postby Antonis » Tue Aug 30, 2011 9:54 pm

Hello I am trying to add the app icon left of the title, then a separator and then everything you have but it force closes all the time :\ I also tried to add a third button at the right but it also force closes :\

Could you maybe demonstrate a state example (press and change icon to black one etc?) I can think of a way to do it :\
Antonis
Once Poster
Once Poster
 
Posts: 1
Joined: Wed Jul 27, 2011 11:19 am

Re: Action Bar

Postby Aseriesofsmallprojects » Tue Sep 06, 2011 11:57 pm

@izu516 - thanks for the writeup. It was helpful to get me going on a new project. I nested some LinearLayout objects in the main bar to handle each section - it greatly simplifies the code and makes it easier to add new items.

@Antonis - you need to look at the stack trace in DDMS - it will tell you exactly why it is crashing. It is probably a layout problem - RelativeLayout makes things difficult, since you have to reference other view IDs all over the place.
www.ProjectJourneyman.com - Android development and app marketing
twitter.com/PrjJourneyman Twitter feed
Android Developer Tutorial A growing tutorial for Android Devs
The Android Income Series Books on income topics for Android developers
Aseriesofsmallprojects
Developer
Developer
 
Posts: 39
Joined: Fri Oct 08, 2010 4:29 pm
Location: USA

Top

Re: Action Bar

Postby onlineadr » Thu Sep 08, 2011 6:36 am

will have to try this out... found a library a while ago for an ActionBar
onlineadr
Experienced Developer
Experienced Developer
 
Posts: 59
Joined: Thu Apr 28, 2011 12:45 pm

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 6 guests