【问题标题】:Filter with chips android过滤芯片安卓
【发布时间】:2020-03-16 16:13:10
【问题描述】:

我想问你是否存在一个单选按钮的组件,但它是像这张图片这样的芯片格式。它是您想要搜索游戏时出现在 Google Play 游戏中的一个组件

感谢我们的回复

【问题讨论】:

    标签: android radio-button android-button material-components-android android-chips


    【解决方案1】:

    这不是您正在寻找的,但您可以使用:

    • 圆角容器,如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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-09
      • 1970-01-01
      • 2013-07-17
      • 2011-12-30
      • 1970-01-01
      • 2016-05-03
      相关资源
      最近更新 更多