有没有办法改变芯片文本垂直填充?我深入研究了 api,看起来我们只能使用以下方法更改 startPadding 和 endPadding:
app:chipStartPadding
app:chipEndPadding
app:textStartPadding
app:textEndPadding
Run Code Online (Sandbox Code Playgroud)
那么我们该如何做诸如更改chipTopPadding 或textTopPadding 之类的事情呢?
android material-design android-chips material-components-android
在我使用 AutoCompleteEditText 和 ChipGroup 创建布局后,我试图在我的 Android 应用程序中创建一个 ChipInput,我将动态创建的 Chip 添加到其中,但在堆栈跟踪中出现以下错误:
E/ThemeUtils:视图类 com.google.android.material.chip.Chip 是一个 AppCompat 小部件,只能与 Theme.AppCompat 主题(或后代)一起使用。
此组件上的样式要求您的应用程序主题为 Theme.MaterialComponents(或其后代)。
问题是我的主题尚未设置为材质,但我仍然收到该错误,我什至尝试以编程方式将主题设置为芯片,但仍然出现该错误。
这是我以编程方式添加芯片的代码
private fun addChipToGroup(person: String, chipGroup: ChipGroup) {
val chip = Chip(applicationContext)
chip.text = person
chip.isCloseIconVisible = true
// necessary to get single selection working
chip.isClickable = true
chip.isCheckable = false
chipGroup.addView(chip as View)
chip.setOnCloseIconClickListener { chipGroup.removeView(chip as View) }
}
Run Code Online (Sandbox Code Playgroud)
应用程序在该方法的第一行崩溃
android android-theme kotlin android-chips material-components-android
在 android 中构建切换按钮的最佳方法是什么,如下图所示。我花费的时间比我愿意承认的要多,但到目前为止,似乎不可能同时获得圆形背景和图标。
我的布局
<ToggleButton
android:id="@+id/addButton"
android:layout_width="match_parent"
android:layout_height="45dp"
android:background="@drawable/button_bg_rounded_corners"
android:button="@drawable/check"
Run Code Online (Sandbox Code Playgroud)
查看
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/app_checkmark"
android:state_checked="true" />
<item android:drawable="@drawable/app_close"
android:state_checked="false"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
BG
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape android:shape="rectangle" >
<solid android:color="@color/appcolor_yellow" />
<corners android:radius="20dp" />
</shape>
</item>
<item android:state_checked="false" >
<shape android:shape="rectangle" >
<solid android:color="@color/appcolor_green"/>
<corners android:radius="20dp" />
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
我得到了什么
android android-layout android-button material-components-android
我试图为按钮提供一个图标,但它看起来像这样!
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test Button"
app:icon="@drawable/ic_facebook"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我试图在互联网上找到相关问题,但不幸的是找不到与此问题相关的任何内容,或者我搜索得不够
android android-button material-design material-components-android
我在尝试使用 Jetpack Compose 和 Material3 组件构建新的 Android 应用程序时遇到以下未解决的参考错误。
到目前为止,我已尝试过本页中提到的以下步骤:
我的gradle代码如下:
plugins {
id 'com.android.application'
id 'kotlin-android'
}
android {
compileSdk 31
defaultConfig {
applicationId "com.example.recoverme"
minSdk 21
targetSdk 31
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = …Run Code Online (Sandbox Code Playgroud) android kotlin material-components-android android-jetpack-compose android-jetpack-compose-material3
我目前有一个用 jetpack compose 编写的应用程序,它使用androidx.compose.material:material.
from / import androidx.compose.material.MaterialTheme
@Composable
fun MaterialTheme(
colors: Colors = MaterialTheme.colors,
typography: Typography = MaterialTheme.typography,
shapes: Shapes = MaterialTheme.shapes,
content: @Composable () -> Unit
)
Run Code Online (Sandbox Code Playgroud)
我现在计划迁移到 Material3:(androidx.compose.material3:material3我知道仍处于 alpha 版本)。
但是,主题可组合现在不再允许任何形状
from / import androidx.compose.material3.MaterialTheme
@Composable
fun MaterialTheme(
colorScheme: ColorScheme = MaterialTheme.colorScheme,
typography: Typography = MaterialTheme.typography,
content: @Composable () -> Unit
)
Run Code Online (Sandbox Code Playgroud)
我现在应该如何处理旧的形状定义?材料网站只讨论如何在 xml 和旧视图系统中做到这一点。
material-design material-components-android android-jetpack-compose android-jetpack-compose-material3
Google 推出了 Material 3,它允许用户选择一种颜色来应用于整个系统主题,但他们的文档不清楚,也没有提到如何以编程方式获取当前颜色以用于应用程序,例如更改视图的背景颜色或文字颜色。
例如:view.setBackgroundColor(Material3.getPrimaryColor());
当然Material3.getPrimaryColor()不存在,这只是我需要的一个例子。
如有任何帮助,我们将不胜感激,谢谢。
我通过应用程序迁移到 Material design 1.5.0。我对工具栏使用以下代码(简化):
内部活动:
<include layout="@layout/toolbar_default" />
Run Code Online (Sandbox Code Playgroud)
工具栏_默认值:
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.appbar.MaterialToolbar
...
app:theme="@style/defaultToolbarTheme"
...
/>
Run Code Online (Sandbox Code Playgroud)
款式:
<style name="defaultToolbarTheme" parent="Theme.MaterialComponents.NoActionBar">
<item name="android:textColorPrimary">?app_toolbar_foreground_color</item>
<item name="android:textColorSecondary">?app_toolbar_foreground_color</item>
<item name="android:background">@drawable/item_background_menu</item>
<item name="android:itemTextAppearance">@style/MyActionBar.MenuTextStyle</item>
</style>
<style name="MyActionBar.MenuTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Subtitle" />
Run Code Online (Sandbox Code Playgroud)
项目背景菜单:
<selector>
<item android:drawable="@color/blue_click" android:state_pressed="true"/>
<item android:drawable="@drawable/item_background_menu_drawable"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
item_background_menu_drawable:
<shape>
<solid android:color="itemColor"/>
</shape>
Run Code Online (Sandbox Code Playgroud)
颜色:
<color name="itemColor">#1155a2</color>
Run Code Online (Sandbox Code Playgroud)
迁移之前,工具栏菜单如下所示:
迁移后,菜单项的工具栏列表出现了一些奇怪的顶部和底部边框/填充:
有人可以告诉如何更改此填充的颜色(目前似乎是 Android 菜单中使用的默认灰色),或者更好的是,如何删除此填充?谢谢。
我需要使用芯片制作以下 UI
我已经实现了芯片并使其可检查,但我不知道如何将其样式更改为图片
我更改了笔触颜色和背景颜色以及笔触宽度
所以正常的筹码没有问题,我的问题是检查过的筹码是蓝色的
任何人都可以请教吗?
android material-design android-chips material-components-android
如果将Theme.MaterialComponents.Light设置为主要主题,那么如果在xml布局中使用它们,这两个按钮之间会有什么区别吗?
<Button />
<com.google.android.material.button.MaterialButton />
Run Code Online (Sandbox Code Playgroud)
如我所见,它们的行为均与MaterialButtons相同。如果要获取旧的普通按钮的行为,则必须使用:
<androidx.appcompat.widget.AppCompatButton />
Run Code Online (Sandbox Code Playgroud)
提前致谢!
android android-appcompat android-button material-design material-components-android
material-components-android ×10
android ×9
android-jetpack-compose-material3 ×2
kotlin ×2
java ×1
menu ×1