ImageButton点击改变图片

xml布局文件

activity_main.xml

</pre><pre name="code" class="html"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ImageButton 
        android:id="@+id/image"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/myselector"/>
</LinearLayout>


xml内容选择器

myselector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    
    <item
        android:state_pressed="false"
        android:drawable="@drawable/lianxikefu"/>
    <item 
        android:state_focused="true"
        android:drawable="@drawable/lianxikefu2"/>
    <item 
        android:state_pressed="true"
        android:drawable="@drawable/lianxikefu2"/>
    

</selector>
</pre><div></div><h1><pre name="code" class="java">package com.example.testdemo;

import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

ImageButton点击改变图片_第1张图片 ImageButton点击改变图片_第2张图片



你可能感兴趣的:(imageview)