0

buttons

the first two fields are the SMS applications from android ICS, the third one is mine.
i made this way:

 <RelativeLayout 
  android:layout_width="match_parent"  
  android:layout_height="match_parent" >

   <EditText
    android:id="@+id/searchfield"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_toLeftOf="@+id/newItem"/>

   <ImageButton 
    android:id="@+id/newItem"
    android:layout_height="40dip"
android:layout_width="40dip"
android:layout_alignParentTop="@+id/searchfield"
android:adjustViewBounds="true"
android:contentDescription="Add"
android:layout_alignParentRight="true"/>

 </RelativeLayout>

and the image is setted this way:

 Drawable img = getResources().getDrawable( R.drawable.light_send );
 newItem.setBackgroundDrawable(img);

i'm getting a very bad drawn arrow, and i'm having problems creating the blue background on down. Am i missing something?

1 Answer 1

2

For the ImageButton you want to set the background to a color state list with the colors you are looking for. As for the image you want to do a setImageResource and not a setBackgroundDrawable. That way you can change the ScaleType to adjust how the image is drawn. I would use center_inside to get the best looking arrow. On an ImageButton the background behaves exactly like it does on any view, the image resource is the content and is drawn on top of the background.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.