• Android开发之Toast


    第一次在博客园发布文章,就把我刚弄明白的关于Android开发中的提示设置,分享给大家。

    Toast是Android中经常用到的一个方法,用于简单的用户提示,经过摸索我发现了Toast的两种使用方式,先不扯别的,分享一下,还望大师指教。

    第一种系统默认的方式:

    Toast.makeText(getApplicationContext(), "系统自带提示形式", Toast.LENGTH_SHORT).show();

    第二种自定义方式:

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);//设置显示的位置
    toast.setDuration(Toast.LENGTH_LONG);//设置显示的时间

    toast.setView(getLayoutInflater().inflate(R.layout.activity_two,null));//设置自定义的视图

    toast.show();

    在自定义中显示的视图:

    <LinearLayout
      android:id="@+id/linearLayout1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
    >
      <ImageView
        android:background="@drawable/fire_eye_alien"

        android:layout_width="50dip"
        android:layout_height="50dip"
      />
      <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:text="自定义形式提示"
        android:textSize="20dip"
      />
    </LinearLayout>

    个人感觉对于自定义类型的Toast,难点在于视图的引入,希望大神能给出更多的指导。

  • 相关阅读:
    linux安装nginx
    git配置多个SSH密钥
    webpack加载器安装node-sass失败的解决方法
    Vue-cli webpack打包之后index.html缺少引号的问题
    算法:一个数组中所有元素的最小公倍数
    JS 实现一个睡眠函数sleep
    剑指offer 牛客67道题集合
    剑指offer
    剑指offer
    剑指offer
  • 原文地址:https://www.cnblogs.com/AndroidJotting/p/3888141.html
Copyright © 2020-2023  润新知