android - Xamarin.Forms FindViewById() 返回 null
问题描述
我正在尝试在我所做的 android 项目的布局文件中使用自定义字体创建吐司:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/toastTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:paddingLeft="15dp"
android:fontFamily="@font/made_evolve_sans_light"
android:textColor ="#424242"
android:textSize="25sp"
/>
</LinearLayout>
然后对于我做的自定义吐司:
Toast toast = Toast.MakeText(Application.Context, message, ToastLength.Long);
TextView v = (TextView)toast.View.FindViewById(Resource.Id.toastTextView);
v.SetTextSize(Android.Util.ComplexUnitType.Sp, 25);
toast.View.Background.SetColorFilter(Android.Graphics.Color.ParseColor("#F2e3dace"), PorterDuff.Mode.SrcIn);
toast.SetGravity(GravityFlags.Center, 0, 0);
toast.Show();
但是在运行时,textview v 始终为空。
如何通过 ID 找到带有自定义字体的 textview?
谢谢你!
解决方案
据我所知,来自 toast 的 textview id 是:android.R.id.message
推荐阅读
- ios - 如何在没有索引的情况下访问第 1 层参数缓冲区结构
- laravel - 如何在 Laravel Sail、Docker 上为每个租户创建一个新数据库
- flutter - 如何在飞镖中执行运行时类型转换
- c# - 从内存中正确删除 COM 对象
- reactjs - React - 如何将具有不同名称的道具传递给同一个组件
- python - 如何发送一条错误消息,说明您的命令在 discord.py 中排队
- java - Eclipse 自动完成功能不适用于某些源文件
- javascript - 我想制作一个记录丢失图像的脚本
- kubernetes - kustomize:如何从命令行传递`newTag`
- wso2 - 具有多个参数的 WSO2 MI dataService 嵌套查询