我的Android项目中有一个Java类,用于创建自定义对话框。但是,当我想为自定义对话框布局文件设置文本或其他属性时,我做不到!
当我使用setText更改活动或自定义对话框java类中的对话框布局的textView时,不会发生任何更改。
这是我的自定义对话框布局文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:background="@color/dark_primary"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="@string/alert"
android:textSize="@dimen/alert_title_font_size"
android:textColor="@android:color/white"
android:fontFamily="@font/berlin_regular"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
这是我的对话框生成器Java类:
package com.x.Dialog;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import com.orhanobut.dialogplus.DialogPlus;
import com.orhanobut.dialogplus.OnItemClickListener;
import com.orhanobut.dialogplus.ViewHolder;
import com.x.x.R;
public class CustomAlertDialog {
public Context context;
public Activity activity;
public TextView textView;
在上面的代码textView.setText("Test");中不起作用:它不会更改字段内容。我在xml(@ string / alert)中设置的默认文本仍然显示!
侃侃无极
相关分类