Button的使用(十三):设置可见性

用setVisibility,设置可见传参数View.VISIBLIE,不可见传View.INVISIBLE

package com.example.androidtest;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity  {
	
	OnClickListener listen1 = null;
	OnClickListener listen2 = null;
	Button btn1, btn2;
	
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		btn1 = (Button)findViewById(R.id.button1);
		btn2 = (Button)findViewById(R.id.button2);
		
		listen1 = new OnClickListener() {
			public void onClick(View v) {
				setTitle("Button1");
				btn1.setVisibility(View.INVISIBLE);
				btn2.setVisibility(View.VISIBLE);
			}
		};
		
		listen2 = new OnClickListener() {
			public void onClick(View v) {
				setTitle("Button2");
				btn1.setVisibility(View.VISIBLE);
				btn2.setVisibility(View.INVISIBLE);
			}
		};
		
		btn1.setOnClickListener(listen1);
		btn2.setOnClickListener(listen2);
	}	
}

actiivty_main.xml:


 
  

  


你可能感兴趣的:(android)