首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Android:自定义Toast通知继承默认Toast

Android:自定义Toast通知继承默认Toast
EN

Stack Overflow用户
提问于 2011-12-31 13:02:22
回答 4查看 5K关注 0票数 5

我有一个自定义吐司通知,其中有一个图像和文本。定制的吐司运行良好,但是我想知道如何让我的定制吐司继承默认的吐司外观和感觉?我希望它看起来像一个漂亮的圆角和边框默认的。

这就是我定制的吐司的样子。

代码语言:javascript
运行
复制
<?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>
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2011-12-31 14:21:42

我在我的一个应用程序中使用了这个。改变一些周围的东西,它也应该对你有效。

代码语言:javascript
运行
复制
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();
票数 6
EN

Stack Overflow用户

发布于 2015-11-08 07:10:25

要获得带有漂亮圆角的默认背景(在棒棒糖上),请使用:

代码语言:javascript
运行
复制
android:background="@android:drawable/toast_frame"

代码语言:javascript
运行
复制
android:background="?android:attr/toastFrameBackground"

它会根据安卓的版本给出吐司的背景,如果你想要最新的版本,我建议在..sdk\platforms\android-latest version\data\res\drawable-density下查找toast_frame.9.png文件

文本样式:

代码语言:javascript
运行
复制
    android:textAppearance="@android:style/TextAppearance.Toast"
    android:textColor="@android:color/bright_foreground_dark"
    android:shadowColor="#BB000000"
    android:shadowRadius="2.75"

来源:https://github.com/android/platform_frameworks_base/blob/master/core/res/res/layout/transient_notification.xml

票数 1
EN

Stack Overflow用户

发布于 2011-12-31 14:18:45

尝尝这个

代码语言:javascript
运行
复制
<style name="Themename" parent="android:Theme.dialog">

来自developer.android.com/guide/topics/ui/themes.html

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8686398

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档