android - 为什么我的 ListView/Dialog 不透明?

标签 android android-listview android-fragments android-alertdialog

编辑~ 找到了解决方案并在我的下面的回复中(现在是最后一个回复)但是我要等到两天后才能将其标记为问题的答案。与此同时,我会将此编辑保留在这里,直到我可以将其标记为正确为止。

调用对话框的地方:

public OnClickListener fieldListener = new OnClickListener() {
    public void onClick(View v) {
        FragmentManager fm = getSupportFragmentManager();
        switch (v.getId()) {
        case (0) :

        ChooseDialog ageDialog = new ChooseDialog("Age", ageEditText, act);
        ageDialog.show(fm, "fragment_edit_name");

对话框:

public class ChooseDialog extends DialogFragment implements DialogInterface.OnClickListener, OnMultiChoiceClickListener {

public Dialog onCreateDialog(Bundle savedInstanceState) {
        LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View dialogLayout = inflater.inflate(R.layout.dialog, null);

        AlertDialog.Builder builder;
        switch (editText.getId()) {
        case (0) :
            ListView list = (ListView) dialogLayout.findViewById(R.id.listView1);
        list.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist, 
                activity.getResources().getStringArray(R.array.ageArray)));
        list.setBackgroundColor(00000000);
        builder = new AlertDialog.Builder(activity);
        builder.setTitle(type);
        builder.setNegativeButton("Cancel", this);
        builder.setView(dialogLayout);
        /* builder.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist, 
                    activity.getResources().getStringArray(R.array.ageArray)), 
                    new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    editText.setText(activity.getResources().getStringArray(R.array.ageArray)[which]);
                }} 
                );*/
        return builder.create();

对话框.xml:

<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/listView1"
    android:background="#00000000"
    android:cacheColorHint="#00000000"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>

DialogList.xml(只是适配器的 TextView ):

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:paddingLeft="6dip"
    android:textColor="@color/androidBlue"
    android:paddingRight="10dip"
    android:layout_weight="1"
    android:textAppearance="?android:attr/textAppearanceLarge" />

enter image description here

最佳答案

尝试

list.setBackgroundColor(Color.TRANSPARENT);

编辑:

在浏览几期 ICS 时,我遇到了 this在我看来,这可能是 ICS 的问题。以为这个问题与问题无关,但说明开发者背景设置有问题。

欢迎指正。

关于android - 为什么我的 ListView/Dialog 不透明?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10902085/

相关文章:

android - 在每个 ListView 元素内的 imageView 上添加一个 OnClickListener

android - 如何从 Strings.xml 获取字符串数组的 id,而不直接引用 id

Android 刷新按钮不会出现在操作栏上

Android:当按钮打开时如何将按钮对齐到键盘的底部和上方?

android - 在android库包中包含一个外部库

java - "How to fix this post HTTP request using Android Studio?"

java - 在运行时更改android中ListView的背景颜色

android - 从异步线程更新主线程表布局

android - 通过 findFragmentByTag 从 FragmentManager 获取 DialogFragment

Android - fragment 中的绑定(bind)服务