AlertDialog自定义标题具有黑色边框 [英] AlertDialog custom title has black border

查看:470
本文介绍了AlertDialog自定义标题具有黑色边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an AlertDialog that I use a custom dialog view with. The idea of the custom title view seems simple enough, but there is a black border around the custom title that I can't seem to get rid of. The top, left and right sides have a single-pixel border, while the bottom side has about a 5 pixel border.

使用Java创建对话框:

Creating the dialog in 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();

自定义标题视图布局, part_list_item.xml

Custom title view layout, 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"
    />

我看到的是:

我想要看到的内容:

任何想法?

推荐答案

尝试这样:

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);

这篇关于AlertDialog自定义标题具有黑色边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆