gpt4 book ai didi

android - AlertDialog 自定义标题有黑色边框

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:58:20 25 4
gpt4 key购买 nike

我有一个使用自定义对话框 View 的 AlertDialog。自定义标题 View 的想法似乎很简单,但是自定义标题周围有一个我似乎无法摆脱的黑色边框。顶部、左侧和右侧有一个单像素边框,而底部有大约 5 个像素的边框。

在 Java 中创建对话框:

View titleView = inflater.inflate(R.layout.part_list_item, parent, false);
((TextView) titleView.findViewById(R.id.partName)).setText(titleText);
AlertDialog productDialog = new AlertDialog.Builder(getContext())
.setCustomTitle(titleView)
.setAdapter(adapter, doNothingClickListener)
.create();

自定义标题 View 布局,part_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000"
android:id="@+id/partName"
android:layout_marginLeft="6dip"
android:textAppearance="?android:attr/textAppearanceLargeInverse"
/>

我看到的:

screenshot broken

我想看到的:

screenshot fixed

有什么想法吗?

最佳答案

试试这个:

LayoutInflater inflater = (LayoutInflater)yourClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View titleView = inflater.inflate(R.layout.custom_dialog, null);

((TextView) titleView.findViewById(R.id.partName)).setText("Your Title");
alert1.setCustomTitle(titleView);

关于android - AlertDialog 自定义标题有黑色边框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10222241/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com