Ash*_*ram 8 android android-layout android-chips material-components material-components-android
当我将ChipGroup芯片添加到 XML 时,首先它给了我导致活动崩溃的渲染问题。我通过将 gradle.app 中的支持库版本从implementation 'com.google.android.material:material:1.2.0-alpha05'alpha02 更改为 alpha02 并将 AppTheme 更改为"Theme.MaterialComponents.Light.DarkActionBar".
**现在的问题是,在androidStudio的设计部分,芯片的形状是默认的,即圆形,但在模拟器和实际设备上,它是菱形的。我尝试了该app:chipCornerRadius="5dp"属性,但没有给出预期的结果。
如何将芯片的形状更改为圆形/默认?**
<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=".ui.our_team.OurTeamActivity">
<HorizontalScrollView
android:id="@+id/horizontalScrollView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:scrollbars="none"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chipGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
app:singleLine="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.chip.Chip
android:id="@+id/chip4"
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:chipCornerRadius="5dp"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text="One Choice"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
<com.google.android.material.chip.Chip
android:id="@+id/chip5"
style="@style/Widget.MaterialComponents.Chip.Action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text="Two Action"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
<com.google.android.material.chip.Chip
android:id="@+id/chip6"
style="@style/Widget.MaterialComponents.Chip.Entry"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text="Three Entry"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
<com.google.android.material.chip.Chip
android:id="@+id/chip7"
style="@style/Widget.MaterialComponents.Chip.Filter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:text="Four Filter"
android:textAppearance="@style/TextAppearance.AppCompat.Caption" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)
Gab*_*tti 12
在Chip样式中通过shapeAppearanceOverlay属性定义角的默认值:
<item name="shapeAppearanceOverlay">@style/ShapeAppearanceOverlay.MaterialComponents.Chip</item>
Run Code Online (Sandbox Code Playgroud)
和:
<style name="ShapeAppearanceOverlay.MaterialComponents.Chip" parent="">
<item name="cornerSize">50%</item>
</style>
Run Code Online (Sandbox Code Playgroud)
只需在您的布局中删除app:chipCornerRadius="5dp"。
只需在两个 theme.xml 中添加这一行即可。
<item name="chipCornerRadius">4dp</item>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2170 次 |
| 最近记录: |