Android開發之Toast

來源:互聯網
上載者:User

標籤:horizon   tin   height   ext   duration   strong   使用者   部落格   app   

第一次在部落格園發布文章,就把我剛弄明白的關於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,痛點在於視圖的引入,希望大神能給出更多的指導。

Android開發之Toast

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.