我主要是看了密西西比河谷州立大学的Android视频,这是那个视频上的第二个实例程序。因为网上找不到相关的源代码,我就自己写了一个,不太一样,但是功能都有。
Toast的功能是弹出一个消息框。我主要是利用了Toast来实现下面的应用。
实现的界面如下:
点击 show Hello,就会弹出一个Hello的消息框,
点击 show Hello and your name,就会弹出一个Hello以及键入的名字的消息框,
点击 show your name and a pic,就会弹出一个图片和键入的名字的消息框。
实现菜单功能,可以改变字体颜色,可以退出。
下面是源代码,其中,布局文件activity_main.xm和java源代码MainActivity.java以及strings.xml是最终结果。
布局文件activity_main.xm
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<!-- normal edit text,you can type some strings here -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:"
/>
<EditText
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/type"
/>
</LinearLayout>
<Button
android:id="@+id/btn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/OK1"
/>
<Button
android:id="@+id/btn2"
android:layout_width="fill_parent"
android:layout_height=