Feb 16, 2011

ImageButton

ImageButton displays a button with an image (instead of text) that can be pressed or clicked by the user. By default, an ImageButton looks like a regular Button, with the standard button background that changes color during different button states. The image on the surface of the button is defined either by the android:src attribute in the XML element or by the setImageResource(int) method.

To remove the standard button background image, define your own background image or set the background color to be transparent.

ImageButton

To implement a ImageButton, create three images (for normal, on focus, ad clicked) and place in /drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/imgbutton_3" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/imgbutton_2" /> <!-- focused -->
<item android:drawable="@drawable/imgbutton_1" /> <!-- default -->
</selector>


Create a xml in /drawable folder, named imgbutton.xml here.

Add ImageButton in XML, refer to imgbutton.xml as android:background.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageButton
android:layout_width="100dp"
android:layout_height="wrap_content"
/>
<ImageButton
android:id="@+id/myimagebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/imgbutton"
/>
</LinearLayout>


2 comments:

  1. Dear expert,

    sorry to bother you.
    i will study android API, but can't find the API about query andorid platform codec list?
    just like https://market.android.com/details?id=com.daberi.example.codeclist&rdid=com.daberi.example.codeclist&rdot=1

    ,this APP

    thnaks
    kakabowbow

    ReplyDelete
  2. Hello 九月計劃,

    I can't run the app, CodecList, in my Nexus One; sorry!

    May be this one can help: Android Supported Media Formats.

    I'm not expert!

    ReplyDelete

Infolinks In Text Ads