zoukankan      html  css  js  c++  java
  • demo16Toast

    /Users/alamps/AndroidStudioProjects/demo16Toast/demo16Toast/src/main/res/layout/activity_main.xml
    
    <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"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingBottom="@dimen/activity_vertical_margin"
        tools:context=".MainActivity">
    
    
    
        <Button android:id="@+id/_shortShow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Short Toast" />
    
        <Button android:id="@+id/_longShow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Long Toast" />
    
        <Button android:id="@+id/_customShow"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="customShow Toast" />
    
    
    </LinearLayout>
    ================
    /Users/alamps/AndroidStudioProjects/demo16Toast/demo16Toast/src/main/java/com/example/demo16toast/MainActivity.java
    
    package com.example.demo16toast;
    
    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Gravity;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.LinearLayout;
    import android.widget.Toast;
    
    public class MainActivity extends Activity {
        private Button shortShow;
        private Button longShow;
        private Button customShow;
    
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            this.shortShow = (Button)super.findViewById(R.id._shortShow);
            this.longShow = (Button)super.findViewById(R.id._longShow);
            this.customShow = (Button)super.findViewById(R.id._customShow);
    
            this.shortShow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(MainActivity.this,"Short Toast show ",Toast.LENGTH_SHORT).show();
    
                }
            });
    
            this.longShow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Toast.makeText(MainActivity.this,"Long Toast Show ",Toast.LENGTH_LONG).show();
                }
            });
    
            this.customShow.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                 Toast customToast= Toast.makeText(MainActivity.this,"Custom Toast show ",Toast.LENGTH_LONG);
    
                customToast.setGravity(Gravity.CENTER,60,30);
    
                LinearLayout customToastView =(LinearLayout)customToast.getView();
                ImageView customImageView= new ImageView(MainActivity.this);
                customImageView.setImageResource(R.drawable.ic_launcher);
                customToastView.addView(customImageView,0);//在文字上方填加图片View
                customToast.show();
                }
            });
    
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.main, menu);
            return true;
        }
        
    }
  • 相关阅读:
    代码手动修改约束(AutoLayout)
    iOS开发中手机号码和价格金额有效性判断及特殊字符的限制
    Mac下如何显示隐藏文件/文件夹
    Exp8 Web综合 20181308
    20181308 邵壮 Exp7 网络欺诈防范
    20181308 邵壮 Exp6 MSF应用基础
    重现Vim任意代码执行漏洞(CVE-2019-12735) 20181308
    密码引擎-加密API研究 20181308邵壮
    密码引擎-加密API实现与测试 20181308邵壮
    Exp5 信息搜集与漏洞扫描 20181308邵壮
  • 原文地址:https://www.cnblogs.com/alamps/p/5272730.html
Copyright © 2011-2022 走看看