删除dialogfragment中的白色背景 [英] remove white background in dialogfragment
本文介绍了删除dialogfragment中的白色背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我叫DialogFragment的方式:
Here's how I called my DialogFragment:
DialogSelectAccount myDiag=new DialogSelectAccount();
myDiag.show(ft,"Diag" );
这是(部分地)创建我的DialogFragment的方式:
Here's how (partially) my DialogFragment is created:
public class DialogSelectAccount extends DialogFragment {
public DialogSelectAccount() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setRetainInstance(true);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.dialog_select_account, container, false);
tvMessage = (TextView) rootView.findViewById(R.id.tvMessage);
btnAccountPublic = (Button) rootView.findViewById(R.id.btnAccountPublic);
btnAccountEnterprise = (Button) rootView.findViewById(R.id.btnAccountEnterprise);
tvMessage.setText(message);
btnAccountPublic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Login.setAccountType = 2;
dismiss();
}
});
btnAccountEnterprise.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Login.setAccountType = 1;
dismiss();
}
});
return rootView;
}
这是我的DialogSelectAccount的xml
and here's the xml for my DialogSelectAccount
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff26b4e9"
android:orientation="vertical" >
<TextView
android:id="@+id/tvMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="10dp"
android:textColor="@android:color/black"
android:textSize="15dp"
android:textAlignment="center"
android:gravity="center_horizontal"
android:background="#ff26b4e9"
android:autoText="true">
</TextView>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#ff26b4e9"
android:orientation="horizontal" >
<Button
android:id="@+id/btnAccountPublic"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:clickable="true"
android:text="@string/accountPub"
android:textColor="#ffffffff"
android:background = "@drawable/roundedbutton" />
<Button
android:id="@+id/btnAccountEnterprise"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:clickable="true"
android:text="@string/accountEnt"
android:textColor="#ffffffff"
android:background = "@drawable/roundedbutton" />
</LinearLayout>
</LinearLayout>
问题在于总是显示出令人讨厌的白色背景,如下所示.如何删除它?
the problem is there's always an innoying white background displayed, as shown below. How do I remove it?
推荐答案
在您的DialogFragment
的onCreateView()
中,替换
View rootView = inflater.inflate(R.layout.dialog_select_account, container, false);
使用
View rootView = inflater.inflate(R.layout.dialog_select_account, container);
此外,将其添加到onViewCreated()
:
getDialog().requestWindowFeature(Window.FEATURE_NO_TITLE);
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme);
并在XML的最外层LinearLayout
中进行更改
and in the outermost LinearLayout
of the XML, change
android:layout_width="fill_parent"
android:layout_height="fill_parent"
到
android:layout_height="wrap_content"
android:layout_width="wrap_content"
尝试一下.这应该起作用.
Try this. This should work.
这篇关于删除dialogfragment中的白色背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文