吐司背景改变,以配合活动的主题 [英] Toast background changing to match Activity's Theme

查看:181
本文介绍了吐司背景改变,以配合活动的主题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个自定义的主题我的活动,他们都使用。在这个主题,我设置的android:背景,而这种情况造成任何对话或吐司消息看起来很奇怪。

I have created a custom theme for my activities that they all use. In the theme, I set android:background, and this happens to cause any dialog or toast message to look very strange.

我如何prevent烤面包和吸收主题的属性中的其他对话?

How do I prevent toast and the other dialogs from absorbing the theme's properties?

推荐答案

您可以很容易地通过以下code创建自定义敬酒:

You can easily create custom toast by the following code:

Toast toast = Toast.makeText(context, resTxtId, Toast.LENGTH_LONG);
View view = toast.getView();
view.setBackgroundResource(R.drawable.custom_bkg);
TextView text = (TextView) view.findViewById(android.R.id.message);
/*here you can do anything with text*/
toast.show();

或者你可以实例化一个完全自定义的敬酒:

Or you can instantiate a completely custom toast:

Toast toast = new Toast(context);
toast.setDuration(Toast.LENGTH_LONG);

LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
View view = inflater.inflate(R.layout.custom_layout, null);
toast.setView(view);
toast.show();

对话框定制是一个更复杂的程序。但有类似的解决办法。

Dialog customizing is a more complex routine. But there is similar workaround.

这篇关于吐司背景改变,以配合活动的主题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆