相关疑难解决方法(0)

如何在android中制作带圆角的自定义对话框

我想做的是:我正在尝试制作自定义对话框.圆角.

什么是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)

android android-custom-view android-dialog

94
推荐指数
14
解决办法
10万
查看次数

MaterialCardView 的不同角半径值

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

10
推荐指数
3
解决办法
5273
查看次数

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)

android

9
推荐指数
1
解决办法
4621
查看次数

Android BottomSheetDialogFragment在圆角后面有颜色

我正在使用BottomSheetDialogFragment,我正在绕着右上/左上角,它正常工作但我注意到在圆角后面,它不透明,而且非常烦人.

它在下面的截图中很明显:

在此输入图像描述

我如何让它们透明?

android bottom-sheet

7
推荐指数
2
解决办法
1018
查看次数

如何在BottomSheetDialogFragment中设置最大高度?

在此处输入图片说明我有一个BottomSheetDialogFragment,我需要在这个对话框中设置我的高度。我需要,当用户点击按钮时,对话框会出现并填满屏幕的 85%。这该怎么做?

java android bottom-sheet material-components android-bottomsheetdialog

7
推荐指数
3
解决办法
9057
查看次数

在卡片视图中使用时,Android 中带有圆角的持久性底部工作表会崩溃

我在 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

6
推荐指数
2
解决办法
5083
查看次数

如何使底部工作表对话框的角变圆?

我试图使我的 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)

我似乎没有做任何工作。有人能指出我正确的方向吗?

java android material-design android-bottomsheetdialog

6
推荐指数
2
解决办法
4133
查看次数

BottomSheetDialogFragment 的圆角不适用于 API &lt;21

我正在使用此解决方案来圆角对话框中的圆角,BottomSheetDialogFragment它在 API 21 及更高版本中运行良好

在此处输入图片说明

但是在 Api < 21 中,它删除了背景并且圆角背景消失了。 在此处输入图片说明 如何在 API < 21 中使背景四舍五入?如果无法更改背景,请帮我更改背景颜色。

android bottom-sheet

1
推荐指数
1
解决办法
7835
查看次数