zoukankan      html  css  js  c++  java
  • 2.6.1 使用toast显示提示信息框

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:orientation="vertical" >
    
        <Button
            android:id="@+id/btn1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="普通toast" />
    
        <Button
            android:id="@+id/btn2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal" 
            android:text="带image的toast">
        </Button>
    
    </LinearLayout>
    package com.moon.hello2;
    
    import java.util.ArrayList;
    import java.util.Calendar;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.zip.Inflater;
    
    import android.R.anim;
    import android.R.bool;
    import android.R.integer;
    import android.animation.AnimatorSet.Builder;
    import android.app.Activity;
    import android.app.AlertDialog;
    import android.app.DatePickerDialog;
    import android.app.DatePickerDialog.OnDateSetListener;
    import android.app.ProgressDialog;
    import android.app.TimePickerDialog.OnTimeSetListener;
    import android.app.Dialog;
    import android.app.TimePickerDialog;
    import android.content.DialogInterface;
    import android.content.res.TypedArray;
    import android.database.DataSetObserver;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.view.Gravity;
    import android.view.Menu;
    import android.view.View;
    import android.view.ViewGroup;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup.LayoutParams;
    import android.view.animation.AnimationUtils;
    import android.widget.AbsListView;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemClickListener;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    import android.widget.BaseAdapter;
    import android.widget.Button;
    import android.widget.DatePicker;
    import android.widget.ExpandableListAdapter;
    import android.widget.ExpandableListView;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.ListView;
    import android.widget.PopupWindow;
    import android.widget.ProgressBar;
    import android.widget.RatingBar;
    import android.widget.SimpleAdapter;
    import android.widget.TableLayout;
    import android.widget.Toast;
    import android.widget.RatingBar.OnRatingBarChangeListener;
    import android.widget.SeekBar;
    import android.widget.DatePicker.OnDateChangedListener;
    import android.widget.SeekBar.OnSeekBarChangeListener;
    import android.widget.TabHost;
    import android.widget.TextView;
    import android.widget.TimePicker;
    import android.widget.TimePicker.OnTimeChangedListener;
    import android.widget.ViewSwitcher.ViewFactory;
    
    public class MainActivity extends Activity {
        private ProgressDialog progressDialog = null;
        private int progress = 0;
        private Handler handler = null;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            this.setContentView(R.layout.activity_main);
            findViewById(R.id.btn1).setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    MainActivity.this.getNormalToast().show();
                }
            });
            findViewById(R.id.btn2).setOnClickListener(new OnClickListener() {
                
                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub
                    MainActivity.this.getSpecialToast().show();
                }
            });
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
    
        private Toast getNormalToast() {
            return Toast.makeText(this, "这是一个简单的toast", Toast.LENGTH_SHORT);
        }
        
        private Toast getSpecialToast(){
            Toast toast = Toast.makeText(this, "这是一个带图片的toast", Toast.LENGTH_SHORT);
            LinearLayout layout = new LinearLayout(this);
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(R.drawable.ic_launcher);
            View toastView = toast.getView();
            layout.addView(imageView);
            layout.addView(toastView);
            toast.setView(layout);
            return toast;
        }
    }
  • 相关阅读:
    LOJ.114.K大异或和(线性基)
    BZOJ.2115.[WC2011]Xor(线性基)
    BZOJ.2460.[BeiJing2011]元素(线性基 贪心)
    Codeforces Round #494 (Div 3) (A~E)
    Codeforces Round #493 (Div 2) (A~E)
    BZOJ.3238.[AHOI2013]差异(后缀自动机 树形DP/后缀数组 单调栈)
    BZOJ.4180.字符串计数(后缀自动机 二分 矩阵快速幂/倍增Floyd)
    BZOJ.1396.识别子串(后缀自动机/后缀数组 线段树)
    BZOJ.3489.A simple rmq problem(主席树 Heap)
    BZOJ.4566.[HAOI2016]找相同字符(后缀自动机)
  • 原文地址:https://www.cnblogs.com/Moon-Face/p/4533716.html
Copyright © 2011-2022 走看看