用筹码过滤 android

Filter with chips android

我想问你是否存在于组件中,它是一个单选按钮,但它是来自芯片的格式,就像这张图片。它是 Google Play Games 中的一个组件,当你想搜索游戏时

感谢我们的回复

这不是您要查找的内容,但您可以使用:

  • 带有圆角的容器,例如 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>

与:

  <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);