java – 如何在我的自定义吐司中获得吐司的浅蓝色光环?
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 如何在我的自定义吐司中获得吐司的浅蓝色光环?,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2699字,纯文字阅读大概需要4分钟。
内容图文
![java – 如何在我的自定义吐司中获得吐司的浅蓝色光环?](/upload/InfoBanner/zyjiaocheng/791/efd89495110141c6960884f02e880312.jpg)
我正在创建我的自定义吐司主要是因为我将它放在网格视图上并需要对其宽度进行一些控制.但我确实喜欢标准吐司上的浅蓝色光环,并希望得到它(或至少让我的自定义吐司看起来有点类似于默认吐司).
实现这一目标的简单/优雅方式是什么?
我从这个布局创建了一个自定义吐司:
<LinearLayout
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:padding="10dp">
<ImageView android:id="@+id/toast_layout_image"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/icon" android:layout_marginRight="10dp">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/toast_layout_text"
android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
</LinearLayout>
并以这种方式调用它(android dev.文档中概述的常用方法以及Web上的几个教程,唯一的区别是我使用网格视图并且每个toast根据其网格图块位置放置):
int location[] = new int[2];
view.getLocationOnScreen(location);
LayoutInflater inflater = getLayoutInflater();
View toastLayout = inflater.inflate(R.layout.toast_layout,(ViewGroup)findViewById(R.id.toast_layout_root));
TextView textView = (TextView) toastLayout.findViewById(R.id.toast_layout_text);
textView.setText("This tile does not contain any valid data.");
int toastWidth = cellWidth * 3 / 4;
textView.setWidth(toastWidth - 64); // TODO picture size needs to be correct
Toast toast = new Toast(getApplicationContext());
toast.setView(toastLayout);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.TOP|Gravity.LEFT, location[0]+((cellWidth-toastWidth)/2),location[1]+cellHeight-100);
toast.show();
这看起来非常干净但与默认吐司完全不同.
解决方法:
将此布局应用于您的Toast消息:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toast_layout_root"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="35dp"
android:orientation="horizontal"
android:background="@android:drawable/dialog_holo_dark_frame" >
<ImageView android:id="@+id/toast_layout_image"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/appicon" android:layout_marginRight="10dp">
</ImageView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/toast_layout_text"
android:textColor="#FFF" android:textAppearance="?android:attr/textAppearanceLarge">
</TextView>
</LinearLayout>
我没有找到cellWidth和cellHeight是什么,所以如果它不适合,尝试尝试填充
编辑:哦,我应用了黑暗主题,试着用光代替.
内容总结
以上是互联网集市为您收集整理的java – 如何在我的自定义吐司中获得吐司的浅蓝色光环?全部内容,希望文章能够帮你解决java – 如何在我的自定义吐司中获得吐司的浅蓝色光环?所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。