<?xml
version="1.0"
encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
android:src="@drawable/android3d"
android:contentDescription="@string/Message"/>
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:padding="10dp"
android:background="#000"
android:textColor="#fff"
android:text="@string/ButtonMessage"/>
</FrameLayout>
package
com.nkaya.test;
import
android.support.v7.app.ActionBarActivity;
import
android.os.Bundle;
import
android.view.Menu;
import
android.view.MenuItem;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.widget.Button;
import
android.widget.EditText;
import
android.widget.ImageView;
import
android.widget.Toast;
public
class
MainActivity extends
ActionBarActivity {
Button
button;
ImageView
image;
/**Called
when the activity is first created.*/
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addListenerOnButton();
}
private
void
addListenerOnButton() {
image=(ImageView)
findViewById(R.id.imageView1);
button=(Button)
findViewById(R.id.btnChangeImage);
button.setOnClickListener(new
OnClickListener() {
public
void
onClick(View v) {
image.setImageResource(R.drawable.android);
}
});
}
}
Comments
Post a Comment