带有Android芯片的过滤器

问题描述 投票:0回答:1

我想问你是否存在于一个单选按钮的组件中,但是它是像这样的图像那样从芯片中格式化的。当您要搜索游戏时,它是Google Play游戏中提供的组件]

enter image description hereenter image description here

感谢我们的回复

android radio-button android-button material-components-android android-chips
1个回答
0
投票

不是您要找的东西,但可以使用:

  • 具有圆角的容器,例如CardViewLinearLayout
  • 每个项目都有一个圆角的单个Button
  • onClick事件上添加动画

类似:

   <LinearLayout
        android:id="@+id/ll_container"
        ..>

             <com.google.android.material.button.MaterialButton
                 style="@style/materialButtonOutlinedStyle"
                  .../>

              <View
                 android:layout_width="1dp"
                 android:layout_height="..."
                 ../>

              <com.google.android.material.button.MaterialButton
                  style="@style/materialButtonOutlinedStyle"
                  ..>

              <!-- ..... -->

        </LinearLayout>

with:

  <style name="materialButtonOutlinedStyle" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="strokeWidth">0dp</item>
    <item name="shapeAppearanceOverlay">@style/rounded_button</item>
    <item name="android:insetTop">0dp</item>
    <item name="android:insetBottom">0dp</item>
  </style>

  <style name="rounded_button">
    <item name="cornerFamily">rounded</item>
    <item name="cornerSize">50%</item>
  </style>

对于容器,您可以使用带有圆角的CardView来包装按钮,也可以简单地将LinearLayout应用于以下内容:

float radius = getResources().getDimension(R.dimen.default_corner_radius);
LinearLayout linearLayout= findViewById(R.id.ll_container);
ShapeAppearanceModel shapeAppearanceModel = new ShapeAppearanceModel()
    .toBuilder()
    .setAllCorners(CornerFamily.ROUNDED,radius)
    .build();

MaterialShapeDrawable shapeDrawable = new MaterialShapeDrawable(shapeAppearanceModel);
shapeDrawable.setFillColor(ContextCompat.getColorStateList(this,R.color.white));
shapeDrawable.setStrokeWidth(1.0f);
shapeDrawable.setStrokeColor(ContextCompat.getColorStateList(this,R.color...));


ViewCompat.setBackground(linearLayout,shapeDrawable);

enter image description hereenter image description here

© www.soinside.com 2019 - 2024. All rights reserved.