问题描述
- android加载自定义dialog,背景总是黑色的。不知道为什么。求解答
-
java代码:LayoutInflater inflater = LayoutInflater.from(getActivity());
View v1 = inflater.inflate(R.layout.progress_dialog_item, null);// 得到加载view
RelativeLayout layout = (RelativeLayout) v1.findViewById(R.id.dialog_view);// 加载布局AsAlertDialog.Builder builder = new AsAlertDialog.Builder(getActivity());
progressDialog = builder.create();progressDialog.show();
progressDialog.setContentView(layout,new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));————————————————————————————————
xml:
<?xml version="1.0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00000000"
android:id="@+id/dialog_view" ><RelativeLayout android:id="@+id/progress_layout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:background="#00000000" > <ProgressBar android:id="@+id/process_bar" style="?android:attr/progressBarStyle" android:layout_width="50px" android:layout_height="50px" android:layout_centerVertical="true" android:indeterminateBehavior="repeat" android:indeterminateDrawable="@drawable/loading_process" android:indeterminateDuration="500" android:indeterminateOnly="true" android:background="#00000000" android:interpolator="@android:anim/linear_interpolator" /> <TextView android:id="@+id/progress_textview" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_marginLeft="10px" android:layout_toRightOf="@id/process_bar" android:gravity="center_vertical" android:text="@string/weather_waiting" android:textColor="#FFFFFF" android:background="#00000000" android:textSize="24px" /> </RelativeLayout>
解决方案
你好,可以在manifest.xml中application节点下设置dialog的主题样式,选用holo.light就OK了
android:theme="@android:style/Theme.Holo.Light.Dialog"
解决方案二:
背景是黑色?难道是因为兼容2.3.3的问题?我之前写了一个可以兼容2.3.3的,可以参考一下:
http://blog.csdn.net/u011596810/article/details/46943025
解决方案三:
我也遇到这个问题了。黑色不太好看。