<Button
android:id="@+id/btnTest"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button"
/>
<TextView
android:id="@+id/myTestText"
android:layout_width="fill_parent"
android:layout_height="30dp"
android:text="welcome"
android:visibility="gone"/>
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
textview.setVisibility(textview.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE);
或者
if(textview.getVisibility() == View.VISIBLE)
textview.setVisibility(View.GONE);
else
textview.setVisibility(View.VISIBLE);
}
});