我有一个底层应该2个状态之间去,STATE_COLLAPSED并且STATE_EXPANDED
当它崩溃了HIGHT应该是200dp,展开的时候它会全屏显示。
所以我设置BottomSheetBehavior与
isFitToContents = false
peekHeight = 200dp
Run Code Online (Sandbox Code Playgroud)
并且我被迫设置一个值,halfExpandedRatio否则当STATE_HALF_EXPANDED底部工作表将占据屏幕的一半时。
我正在工作 com.google.android.material:material:1.1.0-rc01
有没有办法禁用STATE_HALF_EXPANDED状态?
或者我应该实际设置skipCollapsed=true,根据比率计算 200dp 的含义并使用STATE_HALF_EXPANDEDandSTATE_EXPANDED代替STATE_COLLAPSEDandSTATE_EXPANDED
我知道如何使用颜色填充制作材质设计按钮:
style="@style/Widget.AppCompat.Button.Colored"
Run Code Online (Sandbox Code Playgroud)
并且没有边框的透明按钮:
style="@style/Widget.AppCompat.Button.Borderless.Colored"
Run Code Online (Sandbox Code Playgroud)
但是,有没有办法让Material Design设计成边框(透明内部)按钮?像下面的东西?
android button android-button material-design material-components-android
我创建了一些应用程序,我想在其中插入一个 BottomNavigationView。
该代码运行良好,但是一旦我将 gradle 更改为 androidx,它就停止工作了。
我的布局中的组件 (activity_about):
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="@menu/bottom_navigation"
app:itemBackground="@color/colorWhite"
app:itemIconTint="@drawable/bottom_navigation_foreground"
app:itemTextColor="@drawable/bottom_navigation_foreground" />
Run Code Online (Sandbox Code Playgroud)
菜单文件是:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/navigation_library"
android:enabled="true"
app:showAsAction="ifRoom"
android:title="Library"
android:icon="@drawable/ic_home_black_24dp"/>
<item
android:id="@+id/navigation_search"
android:enabled="true"
app:showAsAction="ifRoom"
android:title="Search"
android:icon="@drawable/ic_search_black_24dp"/>
<item
android:id="@+id/navigation_profile"
android:enabled="true"
app:showAsAction="ifRoom"
android:title="Profile"
android:icon="@drawable/ic_account_circle_black_24dp"/>
</menu>
Run Code Online (Sandbox Code Playgroud)
可绘制文件(bottom_navigation_foreground):
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/colorPurpleFont" />
<item android:state_checked="false" android:color="@color/Gray" />
</selector>
Run Code Online (Sandbox Code Playgroud)
我的代码如下:
public class AboutActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);
BottomNavigationView bottomNavigationView = (BottomNavigationView) findViewById(R.id.bottom_navigation);
bottomNavigationView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { …Run Code Online (Sandbox Code Playgroud) android bottomnavigationview material-components material-components-android androidx
如何更改所有按钮的文字颜色?
我知道我可以设置背景颜色如下:
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.DarkActionBar">
...
<item name="colorButtonNormal">@color/buttonColor</item>
</style>
Run Code Online (Sandbox Code Playgroud)
如何为按钮Text执行此操作?
android android-button material-design material-components material-components-android
如何设置所选的com.google.android.material.chip.Chip颜色?我不希望它成为默认的灰色.这是一个单选芯片组.
原始文档在这里
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipgroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
app:checkedChip="@+id/chip_program"
app:chipSpacingHorizontal="32dp"
app:chipSpacingVertical="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/detailText"
app:singleSelection="true">
<com.google.android.material.chip.Chip
android:id="@+id/chip_program"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Program"
app:chipEndPadding="16dp"
app:chipStartPadding="16dp" />
<com.google.android.material.chip.Chip
android:id="@+id/chip_normal"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/program_normal"
app:chipEndPadding="16dp"
app:chipStartPadding="16dp" />
</com.google.android.material.chip.ChipGroup>
Run Code Online (Sandbox Code Playgroud) android material-design android-chips material-components-android
从支持库和材料中尝试芯片组件
com.google.android.support:design:28.0.0-rc01
com.google.android.material:material:1.0.0-rc01
堆栈跟踪
Run Code Online (Sandbox Code Playgroud)android.view.InflateException: Binary XML file line #72: Binary XML file line #72: Error inflating class com.google.android.material.chip.Chip at android.view.LayoutInflater.inflate(LayoutInflater.java:551) at android.view.LayoutInflater.inflate(LayoutInflater.java:429)`
布局
<com.google.android.material.chip.Chip
android:id="@+id/chip"
style="style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/account"
app:closeIconEnabled="true" />`
Run Code Online (Sandbox Code Playgroud) android android-support-library android-chips material-components material-components-android
我目前正在使用 Material Design TextInputLayout OutlinedBox,如下所示:
<android.support.design.widget.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputEditText
android:id="@+id/myEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Title"
android:inputType="text"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我正在尝试Spinner在 TextInputEditText 下添加一个下拉框,并希望保持相同的样式:OutlinedBox。
我看到 Material Design, Material Design Text Fields似乎支持下拉菜单。如此处所示的区域:
我目前正在使用 Spinner 生成下拉菜单。
<Spinner
style="@style/Widget.AppCompat.Spinner.DropDown"
android:id="@+id/option"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:dropDownWidth="match_parent" />
Run Code Online (Sandbox Code Playgroud)
似乎不可能按照 OutlinedBox 设计添加下拉菜单。是否有一个库可以让我实现这一点,或者是否有更好的方法在 Material Design 中实现这一点?
android material-design android-textinputlayout material-components material-components-android
我试图从材料组件主题更改样式属性(像colorPrimaryVariant,colorOnSecondary等等),但我收到以下错误:
Android resource linking failed
Output: C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3835: error: style attribute 'attr/colorPrimaryVariant (aka com.sample.app:attr/colorPrimaryVariant)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3836: error: style attribute 'attr/colorOnPrimary (aka com.sample.app:attr/colorOnPrimary)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3839: error: style attribute 'attr/colorSecondaryVariant (aka com.sample.app:attr/colorSecondaryVariant)' not found.
C:\...\app\build\intermediates\incremental\mergeDebugResources\merged.dir\values\values.xml:3840: error: style attribute 'attr/colorOnSecondary (aka com.sample.app:attr/colorOnSecondary)' not found.
error: failed linking references.
Run Code Online (Sandbox Code Playgroud)
这就是我的主题:
<resources>
<!-- Light application theme -->
<style name="CBTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
<item name="colorPrimary">@color/cbPrimary</item>
<item name="colorPrimaryDark">@color/cbPrimaryDark</item>
<item name="colorPrimaryVariant">@color/cbPrimaryDark</item>
<item name="colorOnPrimary">#FFFFFF</item>
<item name="colorAccent">@color/cbAccent</item>
<item name="colorSecondary">@color/cbAccent</item>
<item name="colorSecondaryVariant">@color/cbAccentLight</item>
<item name="colorOnSecondary">#FFFFFF</item>
<item name="colorError">@color/cbRed</item> …Run Code Online (Sandbox Code Playgroud) android android-theme material-components material-components-android
更新到 Android Gradle 插件版本后,Jetpack Compose 项目的7.2.2默认文件会出现警告:Theme.kt
ViewCompat.getWindowInsetsController is deprecated
Run Code Online (Sandbox Code Playgroud)
此警告来自项目脚手架期间提供的默认实现:
/* snip */
val view = LocalView.current
if (!view.isInEditMode) {
SideEffect {
(view.context as Activity).window.statusBarColor = colorScheme.primary.toArgb()
ViewCompat.getWindowInsetsController(view)?.isAppearanceLightStatusBars = darkTheme // <--- This triggers a deprecation warning
}
}
Run Code Online (Sandbox Code Playgroud)
文档建议使用WindowCompat.getInsetsController- 但该函数需要访问 aview和 a window。
是否有一种简单的方法可以解决此警告而不忽略它?
android kotlin material-components-android android-jetpack-compose
SwitchMaterial所以我在一种布局中使用:
<com.google.android.material.switchmaterial.SwitchMaterial...
Run Code Online (Sandbox Code Playgroud)
Firebase Crashlytics 向我发送垃圾邮件,其中许多用户都收到以下错误
致命异常:java.lang.RuntimeException 无法启动活动 ComponentInfo{...}:android.view.InflateException:二进制 XML 文件行 #324:二进制 XML 文件行 #324:膨胀类 com.google.android.material 时出错。 switchmaterial.SwitchMaterial
由 android.content.res.Resources$NotFoundException 引起,来自可绘制资源 ID #0x7f080047 的文件 res/drawable/abc_switch_thumb_material.xml
应用主题:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">...
Run Code Online (Sandbox Code Playgroud)
材料部:
implementation "com.google.android.material:material:1.6.1"
Run Code Online (Sandbox Code Playgroud)
这是什么意思?
更新
我尝试使用SwitchAndroidX AppCompat 库,但仍然存在与可绘制对象相同的问题:
Fatal Exception: java.lang.RuntimeException Unable to start activity ComponentInfo{****.ui.MainActivity}: android.view.InflateException: Binary XML file line #324: Binary XML file line #324: Error inflating class androidx.appcompat.widget.SwitchCompat
Caused by android.content.res.Resources$NotFoundException Drawable ***:drawable/abc_switch_thumb_material with resource ID #0x7f080047
这太奇怪了,虽然它在我的智能手机上运行良好,但它已经影响了我的 22 个用户
是的,我为发布版本启用了以下两个选项
minifyEnabled true
shrinkResources true
Run Code Online (Sandbox Code Playgroud)
但对于不同的应用程序来说,它一直工作得很好,而且我从来不需要向 …