Android开发学习笔记(三)Android应用界面编程 Toast/SubMenu学习

这篇博客介绍了如何在Android开发中使用Toast显示消息框,并实现SubMenu功能以改变字体颜色和退出应用。通过实例展示了如何创建点击事件,显示不同内容的Toast,以及在布局文件activity_main.xml中区分android:layout_gravity和android:gravity的用法。同时提供了MainActivity.java和strings.xml的源代码示例。
摘要由CSDN通过智能技术生成

我主要是看了密西西比河谷州立大学的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=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值