我想做的是:我正在尝试制作自定义对话框.圆角.
什么是happing:我能够进行自定义对话,但它没有圆角.我尝试添加一个选择器,但我还是不能
Java代码:
private void launchDismissDlg() {
dialog = new Dialog(getActivity(), android.R.style.Theme_Dialog);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dlg_dismiss);
dialog.setCanceledOnTouchOutside(true);
Button btnReopenId = (Button) dialog.findViewById(R.id.btnReopenId);
Button btnCancelId = (Button) dialog.findViewById(R.id.btnCancelId);
btnReopenId.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
btnCancelId.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
dialog.getWindow().setLayout(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
dialog.show();
}
Run Code Online (Sandbox Code Playgroud)
xml代码:
<?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:background="@android:color/white"
android:orientation="vertical" >
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud) MaterialCardView 的每个角半径是否可以有不同的值?如果是这样怎么办?
我尝试了类似下面的代码,但似乎没有任何效果
float radius = getContext().getResources().getDimension(R.dimen.default_corner_radius);
ShapePathModel leftShapePathModel = new ShapePathModel();
leftShapePathModel.setTopLeftCorner(new RoundedCornerTreatment(radius));
leftShapePathModel.setTopRightCorner(new RoundedCornerTreatment(radius));
MaterialShapeDrawable bg = new MaterialShapeDrawable(leftShapePathModel);
container.setBackground(bg);
Run Code Online (Sandbox Code Playgroud)
容器在哪里
@BindView(R.id.container) MaterialCardView container;
Run Code Online (Sandbox Code Playgroud) android android-layout android-cardview material-components material-components-android
如何在片段中设置页边距?
我在片段底部有一个线性布局,现在我想从该线性布局的顶部展开底部片材
android:layout_marginBottom="36dp" 不起作用,底页覆盖线性布局.
这是我的代码:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="36dp"
android:background="@drawable/shadow"
android:layout_gravity="bottom">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_add_white_24dp" />
</LinearLayout>
<LinearLayout
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ff0000"
app:behavior_hideable="true"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_marginBottom="36dp">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) java android bottom-sheet material-components android-bottomsheetdialog
我在 android 中创建了一个持久的底部工作表,目的是显示一个包含有关位置的附加信息的 ListView。我希望工作表有圆角。我得到了大量模态对话框的结果,但没有持久性的结果。是否可能或我应该使用模态版本?
正如这里的答案中所建议的那样,我尝试将其包装在卡片视图中,但是当我尝试打开片段时应用程序崩溃了。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
tools:context=".fragments.MapFragment">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
app:cardCornerRadius="20dp">
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout="@layout/places_autocomplete_item_powered_by_google" />
</androidx.cardview.widget.CardView>
<com.google.android.gms.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="450dp"
app:cardCornerRadius="24dp"
app:cardElevation="8dp"
app:layout_behavior="@string/bottom_sheet_behavior"
app:behavior_hideable="true"
app:behavior_peekHeight="55dp">
<androidx.core.widget.NestedScrollView
android:id="@+id/bottom_sheet"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tvBottomSheet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/placeholder_text"
android:textColor="@color/colorCommon_BLACK"
android:textSize="37sp" />
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) java android material-design bottom-sheet material-components-android
我试图使我的 BottomSheetDialog 的顶角变圆,但我在网上没有任何运气。这就是我希望它的样子:

无论我尝试过什么,我都不断得到这个:

我在这里尝试过该方法并使用 shapeAppearanceLargeComponent (我现在正在使用的)。
这是我的代码:
样式文件
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<!-- Customize your theme here. -->
...
<item name="shapeAppearanceLargeComponent">@style/CustomShapeAppearanceBottomSheetDialog</item>
</style>
<style name="CustomShapeAppearanceBottomSheetDialog" parent="">
<item name="cornerFamily">rounded</item>
<item name="cornerSizeTopRight">16dp</item>
<item name="cornerSizeTopLeft">16dp</item>
</style>
Run Code Online (Sandbox Code Playgroud)
底部导航菜单片段:
public class BottomNavMenuFragment extends BottomSheetDialogFragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_bottom_nav_drawer, container, false);
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我展示片段的方式:
BottomNavMenuFragment navFragment = new BottomNavMenuFragment();
navFragment.show(getSupportFragmentManager(), navFragment.getTag());
Run Code Online (Sandbox Code Playgroud)
我似乎没有做任何工作。有人能指出我正确的方向吗?
我正在使用此解决方案来圆角对话框中的圆角,BottomSheetDialogFragment它在 API 21 及更高版本中运行良好
但是在 Api < 21 中,它删除了背景并且圆角背景消失了。
如何在 API < 21 中使背景四舍五入?如果无法更改背景,请帮我更改背景颜色。