zoukankan      html  css  js  c++  java
  • 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,难点在于视图的引入,希望大神能给出更多的指导。

  • 相关阅读:
    Altium Designer 出现错误提示(警告)adding items to hidden net GND/VCC
    proteus 查找 仿真元件 中英文对照 [持续更新]
    proteus 运行出错,用户名不可使用中文!
    proteus汉化
    proteus怎么仿真?
    keil 怎样新建工程,编写代码?
    raspberry pi2 智能小车源码及测试视频
    项目优化
    PHP composer
    腾讯云通信接入
  • 原文地址:https://www.cnblogs.com/AndroidJotting/p/3888141.html
Copyright © 2011-2022 走看看