标签: material-components

如何使用 MDCTabBar

我用 MDCTabBar 制作了一个应用程序,它看起来很完美,但我不知道如何用它设置 childView 我已经完成的是:

let Tab = MDCTabBar()
Tab.items = [some items]
Tab.itemAppearance = .titles
    Tab.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin, .flexibleTopMargin]

Tab.sizeToFit()
Tab.tintColor = UIColor.green
Tab.barTintColor = UIColor.black
Tab.selectedItem = Tab.items.first
Tab.selectedItem = Tab.items.first
appBar.headerStackView.bottomBar = Tab
Run Code Online (Sandbox Code Playgroud)

ios swift material-components

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

如何在materialbutton中定位图标位置

我正在使用支持库中的 Materialbutton。我希望图标位于文本的右侧?我似乎无法找到如何去做。任何帮助表示赞赏

android android-button material-components material-components-android

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

导航抽屉的圆角背景项目

我想为导航抽屉中的项目提供一个圆角,如下所示:

在此处输入图片说明

这是material.io网站上的材料设计示例

可能吗 ?

android navigation-drawer android-navigationview material-components material-components-android

4
推荐指数
3
解决办法
1520
查看次数

新 com.google.android.material.textfield.TextInputEditText 的全局样式

是否可以在com.google.android.material.textfield.TextInputEditText不为每个组件额外设置的情况下设置新组件的样式?

例如:

对于新的,TextInputLayout我可以通过以下方式全局设置样式:

<style name="Theme.MyTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
                                .
                                .
                                .
    <item name="textInputStyle">@style/MyTextInputLayoutStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我希望TextInputEditText有类似的方式,例如:

<item name="editTextStyle">@style/MyTextInputEditTextStyle</item>
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

是一个类似的帖子,但仅适用于旧的设计支持组件。

android material-design android-textinputlayout material-components material-components-android

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

我不知道我的 Android Studio 发生了什么,我没有任何 Google Material 组件

我的项目运行完美,没有错误,好吧。但是现在我不知道第二天会发生什么,Android Studio 将我标记为“@string/appbar_scrolling_view_behavior”的标签为不存在以前根本没有抛出我没有错误。现在,当我尝试测试我的应用程序时不允许我打开它。

现在尝试卸载 Android Studio删除所有文件夹,尝试创建一个新项目尝试放置 Google Material Buttons,当您再次打开它时,我遇到了同样的错误。有人可以帮助我吗?我不想因为 Android Studio 丢失我的整个项目。

我得到的问题如下。我还附上了我的 style.xml 文件和我的 build.gradle 文件的结构,以及所有按钮的结构示例。我知道我可以实例化我的 MaterialComponents 主题,但我的问题是,如果我这样做了,我的许多依赖项,它们的样式就会停止正常工作。

Logcat 中的错误:

2019-04-20 14:43:56.820 17207-17207/com.raven.okami E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.raven.okami, PID: 17207
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.raven.okami/com.raven.okami.RavenNetwork}: android.view.InflateException: Binary XML file line #23: Binary XML file line #11: Error inflating class com.google.android.material.button.MaterialButton
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2946)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at …
Run Code Online (Sandbox Code Playgroud)

java android gradle material-components

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

带有皮肤的 BottomSheetDialogFragment 主题

如何将BottomSheetDialogFragment主题与其他主题结合?

我的应用程序具有使用主题制作的皮肤。BottomSheetDialogFragment应该有圆角,我使用以下方法实现:

 override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setStyle(BottomSheetDialogFragment.STYLE_NORMAL, R.style.CustomBottomSheetDialogTheme) /* hack to make background transparent */
 }
Run Code Online (Sandbox Code Playgroud)

然后在styles.xml

<style name="CustomBottomSheetStyle" parent="Widget.Design.BottomSheet.Modal">
    <item name="android:background">@android:color/transparent</item>
</style>

<style name="CustomBottomSheetDialogTheme" parent="Theme.MaterialComponents.Light.BottomSheetDialog">
    <item name="bottomSheetStyle">@style/CustomBottomSheetStyle</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是如果我从 扩展,Theme.MaterialComponents.Light.BottomSheetDialog我不会得到我在皮肤主题中定义的配色方案。

那么问题来了:如何在皮肤主题里面定义Dialog主题呢?

android android-theme bottom-sheet material-components material-components-android

4
推荐指数
2
解决办法
3262
查看次数

android 芯片占用额外空间;无法包装

我使用带有动态芯片的芯片组。我希望芯片根据它们的文字被包裹在宽度上。但即使没有填充,它也需要额外的空间。

下面是我的代码:

xml:

<com.google.android.material.chip.ChipGroup
    android:id="@+id/cg"
    android:layout_width="0dp"
    android:layout_weight="75"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp"
    android:layout_marginBottom="5dp"
    android:textColor="@android:color/black"
    android:textStyle="bold"
    android:textSize="12sp"
    app:singleSelection="false"
    app:chipSpacingVertical="5dp"
    app:chipSpacingHorizontal="5dp"
    app:singleLine="false"
    app:chipSpacing="2dp">
Run Code Online (Sandbox Code Playgroud)

这是如何动态添加筹码:

for(int i=0;i<cartoonTypes.length;i++){
    chip = new Chip(this);
    chip.setText(cartoonTypes[i].trim());
    chip.setTextColor(Color.WHITE);
    chip.setChipBackgroundColor(getResources().getColorStateList(R.color.colorChip));
    chip.setTextSize(12);
    chip.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    chip.setPadding(0,0,0,0);
    cgMovieGenre.addView(chip);
    ChipGroup.LayoutParams layoutParams = (ChipGroup.LayoutParams) chip.getLayoutParams();;
    int dpSize = px2dp(12);;
    layoutParams.height = dpSize;
    layoutParams.width = ChipGroup.LayoutParams.WRAP_CONTENT;
    chip.setLayoutParams(layoutParams);
}
Run Code Online (Sandbox Code Playgroud)

方法 px2dp 这样做:

int px2dp(int px){
    metrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(metrics);
    int h = (px * metrics.densityDpi) / DisplayMetrics.DENSITY_DEFAULT;
    return h;
}
Run Code Online (Sandbox Code Playgroud)

build.gradle有以下依赖项:

implementation fileTree(dir: 'libs', include: …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-chips material-components material-components-android

4
推荐指数
2
解决办法
4731
查看次数

如何在自动完成公开的下拉菜单上设置背景颜色?

目前正在使用 Material Design 组件和菜单指南设置 Exposed Dropdown 菜单项。但是,当显示我的自动完成文本视图时,它的背景与我的其他文本字段不同。

我尝试将 TextInputLayout 上的 boxBackgroundColor 属性设置为不同的颜色并修改自动完成 TextView 上的背景。此外,我已经厌倦了查看是否可以修改菜单的弹出主题但没有运气。

 // In the onCreateView of fragment

        ArrayAdapter<String> adapter = new ArrayAdapter<>(getContext(), R.layout.dropdown_menu_popup_item, getResources().getStringArray(R.array.down_payment_method_selection));
        monthsAtEmploymentSelection.setAdapter(adapter);

Run Code Online (Sandbox Code Playgroud)
<com.google.android.material.textfield.TextInputLayout
                style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.ExposedDropdownMenu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginEnd="8dp"
                android:hint="@string/months_at_employment_hint"
                app:boxBackgroundColor="@color/white">

                <AutoCompleteTextView
                    android:id="@+id/months_at_employment_selection"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

            </com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
<!--dropdown_menu_popup_item.xml-->
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp"
    android:ellipsize="end"
    android:maxLines="1"
    android:textAppearance="?attr/textAppearanceSubtitle1"
    android:background="@color/white"/>
Run Code Online (Sandbox Code Playgroud)

我希望背景是透明的或与当前设置为白色的背景相匹配。目前它是与字段不匹配的灰白色。

使用扩展下拉菜单样式时的颜色问题示例

android material-design material-components mdc-components material-components-android

4
推荐指数
2
解决办法
3550
查看次数

更改对话框按钮颜色

有什么方法可以更改默认对话框按钮的颜色,或者我需要为此做自定义对话框吗?

这是我的对话:

private void removeItem(final int position) {
    /** Create dialog which ask if user is sure about delete name from list **/
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Delete player");
    builder.setIcon(R.mipmap.ic_launcher);
    builder.setMessage("Do you want to delete player: \"" + mNameList.get(position).getText1() + "\"?")
            .setCancelable(false)

            /** If user click "ok" button, delete player from list and save changes **/
            .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    mNameList.remove(position);
                    mAdapter.notifyItemRemoved(position);
                    saveData();
                }
            })

            /** If user click "cancel" button, …
Run Code Online (Sandbox Code Playgroud)

android android-alertdialog material-design material-components material-components-android

4
推荐指数
2
解决办法
3711
查看次数

如何在Android中创建圆形轮廓材质按钮?

我正在尝试创建一个带有中心图标的按钮。圆的顶部和底部有点平。有没有一种方法可以不使用转角半径?这是我的按钮布局。

<com.google.android.material.button.MaterialButton
        android:id="@+id/start_dispenser_btn"
        style="@style/Widget.MaterialComponents.Button.OutlinedButton"
        android:layout_width="175dp"
        android:layout_height="175dp"
        android:padding="14dp"
        app:cornerRadius="150dp"
        app:icon="@drawable/ic_play_arrow_black_60dp"
        app:iconGravity="end"
        app:iconSize="150dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toStartOf="@+id/stop_dispenser_btn"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/test_dispenser_container"
        app:strokeColor="@color/background_black" />
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

android android-layout android-button material-components material-components-android

4
推荐指数
2
解决办法
93
查看次数