自定义警告对话框视图无法动态显示设置的内容。

huangapple 未分类评论48阅读模式
标题翻译

Custom alert dialog view does not show things set dynamically

问题

我已经创建了一个警示对话框,其中显示了一个自定义视图,

Java代码

LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.about_me_alert, null);
CircleImageView imageView = view.findViewById(R.id.image);
Glide.with(view).load("https://example.com/example.jpg").into(imageView);
TextView title = view.findViewById(R.id.title);
title.setText("This is a title");
TextView note = view.findViewById(R.id.note);
note.setText("This is a note");
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
builder.setPositiveButton("Okay", (dialog, which) -> dialog.dismiss()).show();

XML布局 - about_me_alert.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/cardbackground"
    android:orientation="vertical">

    <de.hdodenhof.circleimageview.CircleImageView
        android:id="@+id/image"
        android:layout_width="128dp"
        android:layout_height="128dp"
        android:layout_centerHorizontal="true"
        android:layout_margin="8dp" />

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/image"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="8dp"
        android:textColor="@color/white"
        android:textSize="16sp" />

    <TextView
        android:id="@+id/note"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/title"
        android:layout_centerHorizontal="true"
        android:layout_margin="8dp"
        android:textColor="@color/white"
        android:textSize="16sp" />
</RelativeLayout>

当警示对话框显示时,它为ImageView和两个TextView预留了空间,但没有设置文本或图像。

注意:这仅在我为发布制作生产APK时发生,而在我手机上进行测试时不会出现这种情况。

英文翻译

I have made an alert dialog which shows a custom view,

Java Code

LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.about_me_alert, null);
CircleImageView imageView = view.findViewById(R.id.image);
Glide.with(view).load(&quot;https://example.com/example.jpg&quot;).into(imageView);
TextView title = view.findViewById(R.id.title);
title.setText(&quot;This is a title&quot;);
TextView note = view.findViewById(R.id.note);
note.setText(&quot;This is a note&quot;);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
builder.setPositiveButton(&quot;Okay&quot;, (dialog, which) -&gt; dialog.dismiss()).show();

XML Layout- about_me_alert.xml

&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
&lt;RelativeLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
android:layout_width=&quot;match_parent&quot;
android:layout_height=&quot;match_parent&quot;
android:background=&quot;?attr/cardbackground&quot;
android:orientation=&quot;vertical&quot;&gt;

&lt;de.hdodenhof.circleimageview.CircleImageView
    android:id=&quot;@+id/image&quot;
    android:layout_width=&quot;128dp&quot;
    android:layout_height=&quot;128dp&quot;
    android:layout_centerHorizontal=&quot;true&quot;
    android:layout_margin=&quot;8dp&quot; /&gt;

&lt;TextView
    android:id=&quot;@+id/title&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_below=&quot;@+id/image&quot;
    android:layout_centerHorizontal=&quot;true&quot;
    android:layout_marginTop=&quot;8dp&quot;
    android:textColor=&quot;@color/white&quot;
    android:textSize=&quot;16sp&quot; /&gt;

&lt;TextView
    android:id=&quot;@+id/note&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_below=&quot;@+id/title&quot;
    android:layout_centerHorizontal=&quot;true&quot;
    android:layout_margin=&quot;8dp&quot;
    android:textColor=&quot;@color/white&quot;
    android:textSize=&quot;16sp&quot; /&gt;
&lt;/RelativeLayout&gt;

When alert is shown, it reserves space for the imageview, and two textviews but does not set text or image.

NOTE: This only happens when I make a production apk for release, not while I am testing on my phone.

huangapple
  • 本文由 发表于 2020年5月30日 22:08:20
  • 转载请务必保留本文链接:https://java.coder-hub.com/62103607.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定