• Android Toast效果


    Android Toast效果是一种提醒方式,在程序中使用一些短小的信息通知用户,过一会儿会自动消失,实现如下:

    FirstActivity.java

    package org.elvalad.activitytest;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.Window;
    import android.widget.Button;
    import android.widget.Toast;
    
    /**
     * Created by elvalad on 2015/3/26.
     */
    public class FirstActivity extends Activity {
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            /* 隐藏标题栏 */
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.first_layout);
    
            /* 在Activity中使用Toast */
            Button button1 = (Button) findViewById(R.id.button_1);
            button1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(FirstActivity.this, "you click button 1",
                            Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    AndroidMainfest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="org.elvalad.activitytest">
    
        <application android:allowBackup="true" android:label="@string/app_name"
            android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">
    
            <activity android:name=".FirstActivity"
                android:label="This is first activity" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
        </application>
    
    </manifest>

    first_layout.xml

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent" android:layout_height="match_parent">
    
        <Button
            android:id="@+id/button_1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button1" />
    </LinearLayout>
  • 相关阅读:
    Nodejs 开发指南 Nodejs+Express+ejs 开发microblog开发心得
    转载 java学习注意点
    STM32f103的数电采集电路的ADC多通道采集程序
    时间复杂度与空间复杂度
    RS232串口通信详解
    实现扫码登录
    TCP/UDP区别与联系
    Tcp三次握手/四次挥手
    浅谈CSRF攻击方式
    图片淡入淡出
  • 原文地址:https://www.cnblogs.com/elvalad/p/4374772.html
Copyright © 2020-2023  润新知