gpt4 book ai didi

android - 删除dialogfragment中的白色背景

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

这是我调用 DialogFragment 的方式:

DialogSelectAccount myDiag=new DialogSelectAccount();
myDiag.show(ft,"Diag" );

以下是(部分)我的 DialogFragment 的创建方式:

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

<?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>

问题是总是显示一个讨厌的白色背景,如下所示。如何删除它?

enter image description here

最佳答案

DialogFragmentonCreateView() 中,替换

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 中更改

android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:layout_height="wrap_content"
android:layout_width="wrap_content"

试试这个。这应该有效。

关于android - 删除dialogfragment中的白色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28528121/

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