Adding an Icon to the Activity Title

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

Adding an Icon to the Activity Title

Postby s.semeria » Tue May 13, 2008 9:08 am

Hello,

I would like to add an icon to the tile of my activity. I used the FEATURE_RIGHT_ICON with the requestFeature method.

Here is my code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. </span>
  2.  
  3.  
  4.  
  5. public void onCreate(Bundle icicle){
  6.  
  7.  
  8.  
  9.      super.onCreate(icicle);
  10.  
  11.      requestFeature(Window.FEATURE_RIGHT_ICON);
  12.  
  13.      setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON,R.drawable.myicon);
  14.  
  15.      setContentView(R.layout.main);
  16.  
  17.  
  18.  
  19. }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4

I am not able to see any icon.
By the way, I used a 32x32 png as icon... I don't know if it could be important.

Have you got any suggestion?

Thanks a lot,

Regards.

s.semeria
s.semeria
Junior Developer
Junior Developer
 
Posts: 23
Joined: Mon Jan 28, 2008 10:18 am
Location: Italy

Top

Postby plusminus » Wed May 14, 2008 12:26 pm

Hello semeria,

try this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Window  w = getWindow();
  2.  
  3.  
  4.  
  5. w.requestFeature(Window.FEATURE_LEFT_ICON);
  6.  
  7.  
  8.  
  9. setContentView(R.layout.SOMELAYOUT);
  10.  
  11.  
  12.  
  13. w.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Should work with FEATURE_RIGHT_ICON also.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby nono35 » Wed Jul 23, 2008 3:03 pm

I have tried this into a Dialog window, it's good for the left_icon but not for the right_icon, I don't know why...

Otherwise, is it possible to interact with this icon ?
I would like to put a cross icon at the right-up of the title bar in order to close the window, is it possible ?

Thanks for reply :)
nono35
Freshman
Freshman
 
Posts: 4
Joined: Mon Jul 21, 2008 4:40 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 5 guests