用eclipse写一个简单的android程序,要求在模拟器上点一下显示一次helloworld,再点一下就消失了,求代码
1个回答
展开全部
在你的layout里创建一个TextView,设好id和字符串:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text"
android:text="helloworld"
/>
</LinearLayout>
然后代码这样写:
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;
public class Display extends Activity{
private TextView mTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.id.main);
mTextView = (TextView)findViewById(R.id.text);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
if (mTextView.getVisibility() == View.VISIBLE) {
mTextView.setVisibility(View.INVISIBLE);
}
else if (mTextView.getVisibility() == View.INVISIBLE) {
mTextView.setVisibility(View.VISIBLE);
}
return super.onTouchEvent(event);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询