Android 不适用于API
我习惯于在BottomSheetDialogFragment中圆角对话框,它可以很好地使用API 21和更高版本 但在Api<21中,它会删除背景,而圆形背景会消失。 如何使API<21中的背景四舍五入?Android 不适用于API,android,bottom-sheet,Android,Bottom Sheet,我习惯于在BottomSheetDialogFragment中圆角对话框,它可以很好地使用API 21和更高版本 但在Api
如果无法更改背景,请帮助我更改背景颜色。创建自定义可绘制的rounded_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>
</shape>
创建自定义可绘制的rounded_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>
</shape>
Morteza我用下面的代码编写了BottomSheetDialog片段对话框,并在KitKat版本mobile中进行了测试 底页对话框类代码 底部\u表\u modal.xml
试试这个,让我知道@Morteza。愉快的编码。Morteza我用下面的代码编写了使BottomSheetDialog片段对话框旋转的代码,并在KitKat版本mobile中进行了测试 底页对话框类代码 底部\u表\u modal.xml
试试这个,让我知道@Morteza。快乐编码。您可以使用cardview和底部纸张对话框,在那里您可以制作圆角@Morteza@g.brahmaDatta如何删除BottomSheetDialogFragmentbackground的背景?哪个背景@Morteza?@g.brahmaDatta看第二张图片,按钮买卖之间的白色背景@Mortezay您可以使用cardview和底部板材对话框,在那里您可以制作圆角@Morteza@g.brahmaDatta如何删除BottomSheetDialogFragmentbackground的背景?哪个背景@Morteza?@g.brahmaDatta看第二张图片,按钮买卖之间的白色背景@Mortezaa将其添加到代码中使我的片段在单击片段外部时不可解除。将其添加到代码中使我的片段在单击片段外部时不可解除。
public class MyBottomSheetDialog extends BottomSheetDialogFragment {
String string;
static MyBottomSheetDialog newInstance(String string) {
MyBottomSheetDialog f = new MyBottomSheetDialog();
Bundle args = new Bundle();
args.putString("string", string);
f.setArguments(args);
return f;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
string = getArguments().getString("string");
//bottom sheet round corners can be obtained but the while background appears to remove that we need to add this.
setStyle(DialogFragment.STYLE_NO_FRAME,0);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.bottom_sheet_modal, container, false);
TextView tv = (TextView) v.findViewById(R.id.text);
//dialog cancel when touches outside (Optional)
getDialog().setCanceledOnTouchOutside(true);
return v;
}}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/linearLayout"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
//adding background from drawable
android:background="@drawable/rounded_dialog">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center"
android:gravity="center"
android:weightSum="10"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp">
<Button
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:text="Buy"
/>
<Button
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:text="sell"
/>
</LinearLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#444343"/>
<corners android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>
</shape>
public class MainActivity extends AppCompatActivity {
BottomSheetDialogFragment bottomSheetDialogFragment;
Button button;
LinearLayout linearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bottomSheetDialogFragment = MyBottomSheetDialog.newInstance("Bottom Sheet Dialog");
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bottomSheetDialogFragment.show(getSupportFragmentManager(),bottomSheetDialogFragment.getTag());
}
});
}
}