2018年4月5日木曜日

Creating a Custom Toast View

Creating a Custom Toast View
创建自定义Toast视图

 LayoutInflater layoutInflater = getLayoutInflater();
 View view = layoutInflater.inflate(R.layout.toastlayout ,null);
 TextView textView = view.findViewById(R.id.tx);
 textView.setText("Creating a Custom Toast View");
 Toast toast = new Toast(getContext());
 toast.setView(view);
 toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
 toast.setDuration(Toast.LENGTH_LONG);
 toast.show();



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        app:srcCompat="@android:drawable/btn_dialog" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/tx"/>
</LinearLayout>





0 件のコメント: