导航页
创建一个SimpleTextDemo,完成后修改main_activity.xml文件:
<ScrollViewxmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFFFCC">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical">
<Button android:id="@+id/textviewdemo" style="@android:style/Widget.Button.Inset" android:layout_width="fill_parent" android:layout_height="wrap_content" android:onClick="onClick" android:text="@string/textViewDemo"/> </LinearLayout>
</ScrollView> |
此布局文件的根节点为ScrollView布局管理器,并设置背景颜色为米白色(FFFFCC),在ScrollView布局中添加一个LinearLayout布局文件,并设置布局方向orientation为vertical垂直方向布局。最后在LinearLayout布局文件中添加Button,并设置Button的样式、文字、点击事件的方法。
而后在MainActivity中实现onClick(Viewview)方法,并设置每一个View的监听处理。
package lyx.feng.simpletextdemo; ... public void onClick(View view) { switch (view.getId()) { case R.id.textviewdemo: Toast.makeText(this,"Waiting...", Toast.LENGTH_SHORT).show(); break; } }
|
运行结果:
而后要添加测试类的话就可以不要继续新建工程,只要在布局文件中新建按钮,而后在按钮的事件处理中跳转到指定的Activity类即可。
QQ:1208484110