ImageViewとTextViewを使用してAlertDialogを作成します。 私はこれを書いた:ImageViewとTextViewを使用したAlertDialog
TextView textView = FindViewById<TextView>(Resource.Id.txtCustomToast);
string str = "sample text";
textView.Text = str;
Typeface typeP = Typeface.CreateFromAsset(this.Assets, "fonts/BLOTUS.TTF");
textView.SetTypeface(typeP, TypefaceStyle.Normal);
textView.SetTextSize(Android.Util.ComplexUnitType.Sp, 18);
しかし、私はこれを参照してください。私はMainActivity内でのTextViewのサイズ、フォントやテキストを変更したい
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.MyButton);
button.Click += delegate
{
AlertDialog.Builder alertadd = new AlertDialog.Builder(this);
LayoutInflater factory = LayoutInflater.From(this);
View view = factory.Inflate(Resource.Layout.sample, null);
alertadd.SetView(view);
alertadd.SetPositiveButton("To Close", (senderAlert, args) =>
{
Toast.MakeText(this, "Closed", ToastLength.Short).Show();
});
alertadd.Show();
};
}
}
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp">
<ImageView
android:id="@+id/imgCustomToast"
android:layout_width="170dp"
android:layout_height="220dp"
android:background="@drawable/ycp"
android:gravity="center_horizontal"
android:layout_gravity="center"
android:layout_marginRight="10dp" />
<TextView
android:id="@+id/txtCustomToast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="C#"
android:gravity="center_horizontal"
android:layout_gravity="center"
android:textSize="20sp"/>
</LinearLayout>
はMainActivityをエラー:
System.NullReferenceException
テキストビューのサイズ、フォント、およびテキストをプログラムで変更するにはどうすればよいですか?あなたはTextView
方法下記にアクセスすることができます間違った方法を行っている
?それは初期化されていないオブジェクトのように見える –