zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    Apache的Thrift引发的编译思考
    QQ的小秘密
    快速简化Android截屏工作
    Solution of wireless link "PCI unknown" on Centos 7.1
    Java Date Compare
    eclipse集成tomcat日志文件输出配置
    身份证号码验证正则表达式
    curl用法一例 传递代理用户名密码
    HTML 5 placeHolder
    JavaScript(ECMAScript) with 语句
  • 原文地址:https://www.cnblogs.com/elvalad/p/4374772.html
Copyright © 2011-2022 走看看