我希望有一个集中的网格单元格,例如桌面上有6列.在文档中,它说:
默认情况下,网格对齐.您可以添加mdc-layout-grid-align-left或mdc-layout-grid-align-right修饰符类来更改此行为.
然后我输入:
<div class="mdc-layout-grid">
<div class="mdc-layout-grid__inner">
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-3-desktop">first</div>
<div class="mdc-layout-grid__cell mdc-layout-grid__cell--span-3-desktop">second</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在桌面上期待:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|----|----|----|
| ~ | ~ | ~ | first | second | ~ | ~ | ~ |
Run Code Online (Sandbox Code Playgroud)
而不是真正的输出:
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 …Run Code Online (Sandbox Code Playgroud) 我在com.google.android.material:materialandroid x上使用了新的材质组件,但无法为按钮设置自定义背景。
我知道我可以app:backgroundTint用来改变颜色
但是默认背景有一些我想消除的填充,以及android:background用于设置自己的背景的旧方法,但是这种方法不再起作用。
我看了看文档,但是找不到关于此更改的任何提及。
android material-design material-components material-components-android
我正在用Chips做一份清单。我希望可以选择这种芯片,因此,请看https://material.io/develop/android/components/chip/,我可以找到一个“选择芯片”。
由于需要动态创建和添加,因此必须配置特定的颜色,颜色波纹,...
所以我要配置的是:
val chip = Chip(context, null, R.style.CustomChipChoice)
chip.isClickable = true
chip.isCheckable = true
chip.isCheckedIconVisible=false
chip.height = ScreenUtils.dpToPx(40)
chip.chipCornerRadius = (ScreenUtils.dpToPx(20)).toFloat()
chip.chipStrokeWidth = (ScreenUtils.dpToPx(2)).toFloat()
chip.setTextAppearanceResource(R.style.ChipTextStyle)
return chip
Run Code Online (Sandbox Code Playgroud)
我尝试的R.style.CustomChipChoice是:
CustomChipChoice样式
<style name="CustomChipChoice" parent="@style/Widget.MaterialComponents.Chip.Choice">
<item name="chipBackgroundColor">@color/background_color_chip_state_list</item>
<item name="chipStrokeColor">@color/background_color_chip_state_list</item>
<item name="rippleColor">@color/topic_social_pressed</item>
</style>
Run Code Online (Sandbox Code Playgroud)
background_color_chip_state_list
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/topic_social_selected" android:state_checked="true" />
<item android:color="@color/topic_social_pressed" android:state_pressed="true" />
<item android:color="@color/topic_unselected_background" />
</selector>
Run Code Online (Sandbox Code Playgroud)
stroke_color_chip_state_list
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/topic_social_pressed" android:state_checked="true"/>
<item android:color="@color/grey_material2" android:state_checked="false"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
如您所见,我将芯片制作为可点击且可检查的(隐藏不需要的选中图标)。
但是当我测试它时,没有设置颜色。芯片看起来只是默认的颜色(灰度)
这种自定义样式可以在哪里应用或如何应用?
PS:
我进行了快速测试,以查看我的CustomStyle是否格式错误/等。
我通过xml添加了一个视图,并且运行良好。
<android.support.design.chip.Chip
android:id="@+id/test" …Run Code Online (Sandbox Code Playgroud) android kotlin android-chips material-components material-components-android
我正在尝试将这些材料文本字段与框轮廓样式一起使用。我看到有一个名为的属性boxStrokeColor,它允许我仅在文本字段突出显示时设置笔划 ,而未突出显示它似乎从全局主题的colorPrimary值中提取该颜色。
在我们的应用程序中,用户可以为某些视图设置自己的背景颜色,我想将文本字段的笔触颜色更改为合适的对比色。
有没有干净的方法来以编程方式设置未突出显示的框笔触颜色?
android android-textinputlayout material-components material-components-android
Android Studio 3.2.1这是我的布局:
<com.google.android.material.button.MaterialButton
android:id="@+id/bittrexJsonViewButton"
android:layout_width="0dp"
android:layout_height="@dimen/min_height"
android:layout_marginStart="@dimen/half_default_margin"
android:layout_marginEnd="@dimen/half_default_margin"
android:text="@string/json_view"
app:layout_constraintBottom_toBottomOf="@+id/binanceJsonViewButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/binanceJsonViewButton"
app:layout_constraintTop_toTopOf="@+id/binanceJsonViewButton" />
Run Code Online (Sandbox Code Playgroud)
更改MaterialButton的背景,我在styles.xml中更改colorAccent
<item name="colorAccent">@color/colorAccent</item>
Run Code Online (Sandbox Code Playgroud)
真好 是工作。
但是问题是:我不想更改colorAccent。我想为MaterialButton与colorAccent使用不同的背景颜色
属性:
android:background="#aabbcc"
Run Code Online (Sandbox Code Playgroud)
没有帮助。
android android-button material-design material-components material-components-android
我在我的项目中使用 Material Buttons 并尝试使用 alpha 值设置 backgroundTint。
<!-- background_tint.xml -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@android:color/black" android:alpha="0.60"/>
</selector>
<!-- activity_main.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.button.MaterialButton
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Sign in"
app:backgroundTint="@color/background_tint" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然而,生成的按钮在正常状态下看起来很奇怪,按下时甚至更奇怪。

当我将 backgroundTint 设置为特定的灰色阴影(例如 #777777)时,我没有看到这个问题。为什么 alpha 值会发生这种情况?
android material-design material-components material-components-android
android android-button material-design material-components material-components-android
我在用着TextInputLayout。我设置了它的提示来string.xml应用本地化。因此,从下拉列表中更改语言后,我使用recreate()使用所选语言资源刷新整个活动组件的方法,但TextInputLayout提示没有刷新。
如何为 NavigationView 中的项目设置填充。我需要为项目设置 paddingLeft,因为我已经删除了图标。我尝试过的是这个,但它不起作用:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
android:focusable="true"
android:foreground="?attr/selectableItemBackground"
app:headerLayout="@layout/nav_header_navigation_drawer"
app:itemBackground="@drawable/selected_background"
app:itemTextAppearance="@style/Drawer"
app:menu="@menu/activity_navigation_drawer_drawer" />
Run Code Online (Sandbox Code Playgroud)
我的 Drawer.xml 文件样式:
<style name="Drawer">
<item name="android:listPreferredItemPaddingLeft">50dp</item>
<item name="android:textSize">30sp</item>
<item name="android:typeface">serif</item>
</style>
Run Code Online (Sandbox Code Playgroud) android navigationview android-navigationview material-components material-components-android
我正在使用 material.io 中的 MaterialComponents for Android。
我有两个主题(光明和黑暗)。我想显示一个 DatePickerDialog。但这是结果:

这是我如何显示对话框的代码:
private fun selectDeadline() {
val dialog = DateDialog()
val bundle = Bundle()
bundle.putInt("themeId", themeId)
dialog.arguments = bundle
dialog.show(supportFragmentManager, "")
}
class DateDialog : DialogFragment(), DatePickerDialog.OnDateSetListener {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val date = DateTime.now()
val themeId = arguments!!.getInt("themeId")
return DatePickerDialog(activity!!, themeId, this, date.year, date.monthOfYear - 1, date.dayOfMonth)
}
override fun onDateSet(view: DatePicker?, year: Int, month: Int, day: Int) {
deadlineTitle.text = "$year, $month, $day"
}
}
Run Code Online (Sandbox Code Playgroud)
最后但并非最不重要的是,我的主题:
<resources>
<!-- …Run Code Online (Sandbox Code Playgroud)