我到处搜索找到我需要的Chips View库.
需要在具有自动完成功能的EditText内显示芯片.我已经尝试了https://github.com/klinker41/android-chips和https://github.com/DoodleScheduling/android-material-chips但他们认为我将在那里使用联系人(或电子邮件地址)库.事实并非如此,我会将它们用于标签(包含1个字和1个图标).我试图制作我自己的两个库版本,但它们很复杂.
有没有人知道一个具有相同功能并且看起来相同的好的Chips View库?
在我的Android应用中,我有一个看起来像这样的简单芯片。
有没有办法设置边框的颜色使其像这样?
更新:我尝试添加形状,但在布局夸大期间出现异常
<android.support.design.chip.Chip
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/chip_with_border"
android:text="my chip" />
Run Code Online (Sandbox Code Playgroud)
drawable/chip_with_border.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners android:radius="30dp"/>
<stroke android:width="1dp" android:color="#DDDDDD"/>
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
这导致异常
android.view.InflateException:二进制XML文件第32行:错误膨胀了类android.support.design.chip.Chip
android material android-chips material-components material-components-android
我正在尝试在TextView/EditText中格式化Hashtags(比如Material Design Specs中提到的Chips).我可以使用格式化背景ReplacementSpan.但问题是我无法增加TextView/EditText中的行间距.见下图

问题是如何为主题标签添加顶部和底部边距?
这是我在文本中添加背景的代码:
/**
* First draw a rectangle
* Then draw text on top
*/
@Override
public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
RectF rect = new RectF(x, top, x + measureText(paint, text, start, end), bottom);
paint.setColor(backgroundColor);
canvas.drawRoundRect(rect, CORNER_RADIUS, CORNER_RADIUS, paint);
paint.setColor(textColor);
canvas.drawText(text, start, end, x, y, paint);
}
Run Code Online (Sandbox Code Playgroud) 有没有办法改变默认材料的芯片垂直填充或高度?从文档中,我肯定可以找到一种设置最小高度的方法,但是我想使芯片“更薄”,就像这种设计:
android material-design android-chips material-components material-components-android
我正在将材料ChipGroup动态添加到设置为 VERTICAL 方向的父线性布局,但芯片项目似乎是水平添加的。有没有办法让它垂直放置芯片项目?
ChipGroup 类方法的setLayoutDirection()方法似乎没有采用任何支持垂直方向的参数。
我在 ChipGroup 中有 Chips,在 HorizontalScrollView 中有这个 ChipGroup。但我的问题是最后一个芯片上的 marginEnd 不工作!
我尝试以编程方式更改布局参数,但没有成功
<HorizontalScrollView
android:id="@+id/chips_container"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_gravity="center_vertical"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/dividerSmartReplies"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:visibility="visible">
<com.google.android.material.chip.ChipGroup
android:id="@+id/chip_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
app:chipSpacing="8dp"
app:singleLine="true"
app:singleSelection="true">
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_marginStart="8dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
<com.google.android.material.chip.Chip
style="@style/Widget.MaterialComponents.Chip.Choice"
android:layout_width="wrap_content"
android:layout_height="42dp"
android:layout_marginEnd="8dp"
android:textColor="@color/selector_smart_reply_chip_text"
app:checkedIconVisible="false"
app:chipBackgroundColor="@color/selector_smart_reply_chip"
app:chipCornerRadius="21dp"
app:chipStrokeColor="@color/app_base_blue"
app:chipStrokeWidth="1dp" />
</com.google.android.material.chip.ChipGroup>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)
最后一个芯片后我需要额外的空间。ChipGroup 的 padding 有效,但没有预期的 …
我正在使用FlexboxLayout在 android 中显示芯片,但卡在 UI 中,我想在第二行末尾显示芯片数量,如下图所示
根据上面的设计,我想显示芯片直到第二行,并且不适合第二行的芯片应该增加芯片末尾的芯片数量
我检查的是
1- FlexboxLayout setMaxLine(2); 但在这种情况下,UI 只有两条线绘制,第二条线是拉伸
2- FlexboxLayout getFlexLineInternel() - 此 API 给出错误的结果。在行中添加 1 个项目后,行数会增加,然后给出getFlexLineInternel().size() == 2 这意味着视图已添加到第三行中,但我只想限制在 2 行中。
3-尝试使用材料芯片和芯片组-它没有给我在芯片组中绘制的线条数
4- 尝试使用类似于 ChipGroup 的Flowlayout 。没有给我按布局绘制的行数,以便我可以在第二行末尾显示计数
请给我建议什么对我的情况有帮助
这是我的代码
活动搜索标签.xml
<com.google.android.flexbox.FlexboxLayout
android:id="@+id/assetLabelsContainer"
android:layout_width="match_parent"
android:layout_marginLeft="@dimen/size_16"
android:layout_marginRight="@dimen/size_16"
android:layout_height="wrap_content"
app:flexWrap="wrap"/>
Run Code Online (Sandbox Code Playgroud)
LabelSearchActivity.java
public class LabelSearchActivity extends SearchActivity {
@BindView(R.id.assetLabelsContainer)
public FlexboxLayout assetLabelsContainer;
private int COUNTER_LABEL_ID = -1;
private ArrayList<LabelModelParcelableItem> selectedLabels;
private ArrayList<LabelModelParcelableItem> visibleSelectedList;
private CompositeDisposable disposables;
@Override
protected void onCreate(Bundle savedInstanceState) { …Run Code Online (Sandbox Code Playgroud) android flowlayout material-design android-chips android-flexboxlayout
我使用材料组件芯片。在芯片中,我们可以获得关闭图标点击和整个芯片点击事件。但无法找到芯片图标点击。
<com.google.android.material.chip.Chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:textColor="@color/chip_text_color"
app:checkedIconEnabled="false"
app:chipBackgroundColor="@color/chip_background"
app:chipIcon="@drawable/ic_pencil_edit_button"
app:chipIconSize="15dp"
app:chipIconTint="@color/chip_text_color"
app:chipStrokeColor="@color/colorPrimary"
app:chipStrokeWidth="1dp"
app:closeIconTint="@color/colorYellow"
app:iconStartPadding="@dimen/spacing_tiny" />
Run Code Online (Sandbox Code Playgroud)
我正在从我的 API 中获取一个列表,例如 25 个国家/地区的标签,例如德国、英国、法国、意大利等......我想要 2 行,chips每行10个,如果我得到 30 个标签下次我取东西时,我想要 3 排,每排 10 个chips等等...
到目前为止,我还没有找到任何允许我这样做的东西。我快速浏览了一下,Flexbox-Layout但它似乎不符合我的需求,我目前有下面的代码,但我正在考虑用一个Recyclerview
分段
viewModel.videoSelected.observe(viewLifecycleOwner, object : Observer<VideoPage> {
override fun onChanged(videoPage: VideoPage?) {
videoPage?.tags ?: return
val chipGroup = binding.chipGroup
val chipGroupInflater = LayoutInflater.from(chipGroup.context)
val children = videoPage.tags.map { tagName ->
val chip = chipGroupInflater.inflate(R.layout.chip_video_tag, chipGroup, false) as Chip
chip.text = tagName
chip.tag = tagName
chip.setOnClickListener {
Toast.makeText(context, tagName, Toast.LENGTH_SHORT).show()
}
chip
}
for (chip in children) {
chipGroup.addView(chip)
}
} …Run Code Online (Sandbox Code Playgroud) 我正在扩展 Chip 类来为我的lib执行一些绘图,我的用例更复杂,但为了简单起见,假设我只是画一条对角线
我的代码
class MyChip (context: Context,attributeSet: AttributeSet) : Chip(context,attributeSet){
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
//just want to draw a diagonal line
canvas.drawLine(0f,0f,width/1f,height/1f,paint)
}
}
Run Code Online (Sandbox Code Playgroud)
xml
<com.abhinav.chouhan.loaderchipdemo.MyChip
android:layout_width="200dp"
android:layout_height="50dp"
android:textAlignment="center"
android:text="SOME TEXT"/>
Run Code Online (Sandbox Code Playgroud)
当我没有属性时,android:textAlignment="center"一切正常,但是有了该属性,我们无法在芯片上绘制任何内容。我尝试了所有方法,但无法弄清楚为什么会发生这种情况。
请帮忙
android ×10
android-chips ×10
material-components-android ×3
flowlayout ×1
hashtag ×1
margin ×1
material ×1
tags ×1