customer Title Bar

below code we will create app like it.

package com.powenko.Tutorial_ImageButton_changeImageWhenPressed;

import android.app.Activity;

import android.os.Bundle;

import android.view.MotionEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.view.View.OnTouchListener;

import android.widget.ImageButton;

public class Tutorial_ImageButton_changeImageWhenPressedActivity extends Activity {

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

ImageButton Demo_button = (ImageButton)findViewById(R.id.ImageView01);

// when you click this demo button

Demo_button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {

}

});

Demo_button.setOnTouchListener(new OnTouchListener() {

@Override

public boolean onTouch(View v, MotionEvent event) {

switch ( event.getAction() ) {

case MotionEvent.ACTION_DOWN:

v.setBackgroundResource(R.drawable.bluebutton );

break;

case MotionEvent.ACTION_UP:

v.setBackgroundResource(R.drawable.icon );

break;

}

return false;

}

});

}

}

res\layout\main.xml

[PHP]

android:id=”@+id/RelativeLayout01″

android:layout_width=”fill_parent”

android:layout_height=”fill_parent”

xmlns:android=”http://schemas.android.com/apk/res/android”>

android:id=”@+id/ImageView01″

android:background=”@drawable/icon”

android:layout_height=”40dip”

>

[/PHP]

source code:


Tutorial_ImageButton_changeImageWhenPressedActivity

, download here http://code.google.com/p/powenko-android-tutorial/

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply