①,將2張圖片放入 res -> drawable 中,如下所示:
創(chuàng)新互聯(lián)是一家專業(yè)的成都網(wǎng)站建設(shè)公司,我們專注網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、網(wǎng)絡(luò)營銷、企業(yè)網(wǎng)站建設(shè),外鏈,1元廣告為企業(yè)客戶提供一站式建站解決方案,能帶給客戶新的互聯(lián)網(wǎng)理念。從網(wǎng)站結(jié)構(gòu)的規(guī)劃UI設(shè)計到用戶體驗提高,創(chuàng)新互聯(lián)力求做到盡善盡美。
②, 在UI中加入ImageView組建,方法將ImageView拖入到設(shè)計窗,彈出選擇圖片框(UI)
②-1 , 拖ImageView到UI設(shè)計窗
②-2 ,在彈出的“Resources”框中中,選擇需要顯示的圖片,如下
①,這個ImageView的Id為 img_tree
②,代碼
package com.kayer.myfirstdemo;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
public class MainActivity extends Activity {
private TextView txt_t = null;
private Button btn_ok = null;
private ImageView img_tree = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.txt_t = (TextView)this.findViewById(R.id.txt_t);
this.btn_ok = (Button)this.findViewById(R.id.btn_ok);
this.img_tree = (ImageView)this.findViewById(R.id.img_tree);
this.btn_ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CharSequence a = MainActivity.this.txt_t.getText();
if( a.toString() == "Hello World!" ){
MainActivity.this.txt_t.setText( "Aonaufly" );
}else{
MainActivity.this.txt_t.setText( "Hello World!" );
}
Drawable icon_1 = getDrawable( R.drawable.tree123 );
MainActivity.this.img_tree.setImageDrawable( icon_1 );
}
});
}
}
①,初始狀態(tài)
②,點擊按鈕后