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>
  • 相关阅读:
    02方法 课后作业1
    HDU 1518
    POJ 2406
    HDU 1953
    HDU 1272
    POJ -- 3842
    POJ -- 3233 求“等比矩阵”前n(n <=10^9)项和
    POJ ---3070 (矩阵乘法求Fibonacci 数列)
    POJ --- 3613 (K步最短路+矩阵快速幂+floyd)
    POJ --- 2918 求解数独
  • 原文地址:https://www.cnblogs.com/elvalad/p/4374772.html
Copyright © 2011-2022 走看看