標籤: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