Epi*_*aos 5 android toast android-layout
我有一个自定义Toast通知,其中包含图像和文本.自定义吐司工作正常,但我想知道如何使我的自定义吐司继承默认的吐司外观和感觉?我希望它看起来像默认的圆角和边框.
这就是我的定制吐司的样子.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:background="#DAAA">
<ImageView android:id="@+id/chatIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:src="@drawable/ic_chat"/>
<TextView android:id="@+id/text"
android:text="@string/unread_message_toast"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textColor="#FFF"
/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我在我的一个应用程序中使用它.改变一些事情,它也应该适合你.
Toast ImageToast = new Toast(getBaseContext());
LinearLayout toastLayout = new LinearLayout(
getBaseContext());
toastLayout.setOrientation(LinearLayout.HORIZONTAL);
ImageView image = new ImageView(getBaseContext());
image.setImageResource(R.drawable.easter_egg);
toastLayout.addView(image);
ImageToast.setView(toastLayout);
ImageToast.setDuration(Toast.LENGTH_SHORT);
ImageToast.show();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4109 次 |
| 最近记录: |