标签: android-chips

在相对布局中向芯片组添加水平滚动

我在一个组中创建了几个静态芯片。我正在使用此链接 ( https://material.io/design/components/chips.html# ) 作为参考。代码如下:

<RelativeLayout
        android:id="@+id/inputLayout"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:layout_alignParentBottom="true"
        android:background="@android:color/white"
        android:gravity="bottom"
        android:paddingStart="8dp"
        android:paddingTop="8dp"
        android:paddingEnd="8dp"
        android:paddingBottom="9dp">

        <ImageView
            android:id="@+id/sendBtn"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:paddingTop="4dp"
            app:srcCompat="@drawable/chatbot_send_btn" />

        <EditText
            android:id="@+id/queryEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_toStartOf="@+id/sendBtn"
            android:imeOptions="actionSend"
            android:inputType="text"
            android:paddingTop="4dp"
            android:textSize="18sp" />

        <com.google.android.material.chip.ChipGroup
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:layout_above="@id/queryEditText">

            <com.google.android.material.chip.Chip
                style="@style/Widget.MaterialComponents.Chip.Choice"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd" />

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd"
                style="@style/Widget.MaterialComponents.Chip.Choice"/>

            <com.google.android.material.chip.Chip
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="wsfdsd" />

        </com.google.android.material.chip.ChipGroup>

    </RelativeLayout>  
Run Code Online (Sandbox Code Playgroud)

这不会显示所有芯片,它只显示 1 个芯片。如何添加水平滚动?我是否需要动态显示筹码以便我可以添加水平滚动?

android material-design android-chips androidx

10
推荐指数
2
解决办法
7627
查看次数

在android中动态创建Choice Chip

我正在使用 Material Components 来创建 Choice 芯片。我遵循了https://material.io/develop/android/components/chip/文档。有足够的东西可以用 XML 创建芯片,但不知道如何以编程方式创建选择芯片。

我使用以下代码动态创建芯片,但默认情况下它创建动作芯片。

val chip = Chip(activity)
chip.text = ("Chip 1")
chipGpRow.addView(chip)
Run Code Online (Sandbox Code Playgroud)

android android-chips material-components material-components-android

10
推荐指数
3
解决办法
1万
查看次数

将自定义chipDrawable背景设置为Chip

我想将自定义可绘制背景设置为 Chip,就像 chip.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.bg_cutom_drawable));

但它不起作用。它给出了错误

java.lang.UnsupportedOperationException: Do not set the background resource; Chip manages its own background drawable.
Run Code Online (Sandbox Code Playgroud)

它需要一个chipDrawable。如何为其创建chipDrawable。我尝试过,但无法找到解决方案。请建议我将不胜感激。

android-chips

9
推荐指数
1
解决办法
4677
查看次数

如何在android中使用自动完成功能将材料设计芯片添加到输入字段?

我正在尝试使用 AutoCompleteTextView 实现 Material Design Chips,以便在用户单击自动完成建议(如 Gmail 收件人芯片)时在输入字段中添加联系人芯片。

可以在Material Design 网站上看到所需的行为。

我决定从头开始在我的项目中与 AutoCompleteTextView 一起实现 Chips,没有外部库。但是,我没有找到任何说明如何做到这一点的指南。

我尝试创建一个独立的 ChipDrawable,然后将其添加到 AutoCompleteTextView 中,如下所示:

布局

<chip
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:chipIcon="@drawable/ic_avatar_circle_24"
    android:text="@string/contact_name"/>
Run Code Online (Sandbox Code Playgroud)

Java代码

ChipDrawable chip = ChipDrawable.createFromResource(getContext(), R.xml.standalone_chip);

chip.setBounds(0, 0, chip.getIntrinsicWidth(), chip.getIntrinsicHeight());
DrawableMarginSpan span = new DrawableMarginSpan(chip, 25);

Editable text = editText.getText();
text.setSpan(span, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
Run Code Online (Sandbox Code Playgroud)

不幸的是,它没有按预期工作。首先,我不能添加更多的芯片。此外,芯片的样式非常奇怪(高度太大,未居中)。

那么如何使用 Material Design Input Chips 创建 Gmail 或 SMS 应用程序中的 Contact Chips 呢?也许有人知道一些实施指南?

提前致谢,您的帮助将不胜感激!

android autocompletetextview material-design android-chips material-components

9
推荐指数
1
解决办法
3099
查看次数

如何从ChipGroup获取精选芯片?

我在互联网上搜索了很多,但找不到确切的解决方案。这是我上次从 SO 尝试的链接。 从 ChipGroup 中获取选定的 Chips

我想在单击按钮时从芯片组中获取选定的芯片。

此函数包含在 RecyclerView 中显示名称的信息

private void getNames() {
    List<String> names = Arrays.asList(getResources().getStringArray(R.array.names));
    int count = 0;
    for ( String name : names){
        list.add(new Names(name));
        count++;
    }
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    namesAdapter = new NamesAdapter(MainActivity.this, list);
    recyclerView.setAdapter(namesAdapter);
}
Run Code Online (Sandbox Code Playgroud)

当单击 RecyclerView 项时,将一个芯片添加到 ChipGroup 中,这是功能

public void onItemSelected(Names name) {
    Chip chip = new Chip(this);
    chip.setText(name.getName());
    chip.setCloseIconVisible(true);
    chip.setCheckable(false);
    chip.setClickable(false);
    chip.setOnCloseIconClickListener(this);
    chipGroup.addView(chip);
    chipGroup.setVisibility(View.VISIBLE);
}
Run Code Online (Sandbox Code Playgroud)

这是ChipGroup展示芯片的图片

从 ChipGroup 获取值的函数

public void getChipGroupValues(){
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View …
Run Code Online (Sandbox Code Playgroud)

java android android-chips material-components material-components-android

9
推荐指数
2
解决办法
1万
查看次数

使用搜索视图的特定标题(从 api 获取)?

我想要这样的东西:

所以问题是,我真正想要的是当用户在搜索视图中输入特定主题名称(如果存在于应用程序中)时,它应该能够提供建议,如果找到它应该打开该主题活动(就像 Facebook、Instagram 等)搜索..这些标题来自API(我已在其他活动中成功显示)..像这样:

..它的逻辑是什么???需要帮助...谢谢

所以我刚刚像这样在 XML 中包含了 searchview-->

  <SearchView
    android:id="@+id/searchView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:queryHint="Search Here"
    android:iconifiedByDefault="false"
    android:layout_alignParentTop="true"
    android:background="@drawable/search_bar"
    android:layout_marginLeft="15dp"
    android:layout_marginRight="15dp"
    android:layout_marginTop="20dp"
    android:pointerIcon="crosshair"
    android:theme="@style/Widget.AppCompat.SearchView"
    android:focusedByDefault="true"
    />
Run Code Online (Sandbox Code Playgroud)

需要帮助...提前致谢....

这是我的 json:

[{"id":"11","title":"TextView"},{"id":"10","title":"Edit Text"},{"id":"9","title":"ImageView"},{"id":"8","title":"Button "},{"id":"7","title":"CheckBox"},{"id":"6","title":"RadioButton & RadioGroup"},{"id":"5","title":"DatePicker"},{"id":"4","title":"TimePicker"},{"id":"3","title":"Switch"},{"id":"1","title":"Simple & Custom Toast"}]
Run Code Online (Sandbox Code Playgroud)

这是我的活动:对于

public class StartLearning extends AppCompatActivity {
private RecyclerView recyclerView;
private SLAdapter slAdapter;
ProgressDialog progressDialog;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.startlearning_layout);
    progressDialog = new ProgressDialog(StartLearning.this);
    progressDialog.setMessage("Loading....");
    progressDialog.show();
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    if (getSupportActionBar() != …
Run Code Online (Sandbox Code Playgroud)

android android-studio retrofit android-chips retrofit2

9
推荐指数
1
解决办法
2834
查看次数

芯片组OnCheckedChangeListener()未触发

我正在尝试基于ChipGroup和Chip创建一个recyclerview过滤器

在此处输入图片说明

我在应用程序上使用片段,因此,包含RecyclerView的片段包含一个将ChipGroup过滤器片段充气的frameLayout

我试图在用户取消选择ChipGroup内的所有芯片时触发侦听器(我已经将侦听器放在芯片上以供用户检查芯片时触发)

我已经在芯片组上放置了一些侦听器,但没有人触发

FilterFragment.java

public class FilterFragment extends Fragment {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
public ChipGroup chipGroup;

// TODO: Rename and change types of parameters
public View.OnClickListener chipClickListener;

private OnFragmentInteractionListener mListener;

public FilterFragment() {
    // Required empty public constructor
}


public static FilterFragment newInstance(View.OnClickListener 
param1) {
    CoachFilterFragment fragment = new CoachFilterFragment();
    Bundle args = new Bundle();

    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); …
Run Code Online (Sandbox Code Playgroud)

android android-chips

8
推荐指数
2
解决办法
4568
查看次数

如何更改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" /> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-chips material-components material-components-android

8
推荐指数
2
解决办法
2170
查看次数

以编程方式更改Chip Widget样式不起作用-Android

我正在用Chips做一份清单。我希望可以选择这种芯片,因此,请看https://material.io/develop/android/components/chip/,我可以找到一个“选择芯片”。

由于需要动态创建和添加,因此必须配置特定的颜色,颜色波纹,...

所以我要配置的是:

val chip = Chip(context, null, R.style.CustomChipChoice)
            chip.isClickable = true
            chip.isCheckable = true
            chip.isCheckedIconVisible=false
            chip.height = ScreenUtils.dpToPx(40)
            chip.chipCornerRadius = (ScreenUtils.dpToPx(20)).toFloat()
            chip.chipStrokeWidth = (ScreenUtils.dpToPx(2)).toFloat()
            chip.setTextAppearanceResource(R.style.ChipTextStyle)
            return chip
Run Code Online (Sandbox Code Playgroud)

我尝试的R.style.CustomChipChoice是:

CustomChipChoice样式

<style name="CustomChipChoice" parent="@style/Widget.MaterialComponents.Chip.Choice">
        <item name="chipBackgroundColor">@color/background_color_chip_state_list</item>
        <item name="chipStrokeColor">@color/background_color_chip_state_list</item>
        <item name="rippleColor">@color/topic_social_pressed</item>
</style>
Run Code Online (Sandbox Code Playgroud)

background_color_chip_state_list

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/topic_social_selected" android:state_checked="true" />
    <item android:color="@color/topic_social_pressed" android:state_pressed="true" />
    <item android:color="@color/topic_unselected_background" />
</selector>
Run Code Online (Sandbox Code Playgroud)

stroke_color_chip_state_list

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/topic_social_pressed" android:state_checked="true"/>
    <item android:color="@color/grey_material2" android:state_checked="false"/>
</selector>
Run Code Online (Sandbox Code Playgroud)

如您所见,我将芯片制作为可点击且可检查的(隐藏不需要的选中图标)。

但是当我测试它时,没有设置颜色。芯片看起来只是默认的颜色(灰度)

这种自定义样式可以在哪里应用或如何应用?

PS:

我进行了快速测试,以查看我的CustomStyle是否格式错误/等。

我通过xml添加了一个视图,并且运行良好。

<android.support.design.chip.Chip
                android:id="@+id/test" …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-chips material-components material-components-android

7
推荐指数
3
解决办法
1262
查看次数

android Chip材料组件顶部和底部的额外空间

我在我的布局中使用芯片视图
自从材料设计组件从1.0.0升级到1.1.0 后,视图的顶部底部有一个额外的空间
我找不到任何关于如何删除这些空间的文档

在材料 1.0.0

在此处输入图片说明

在材料 1.1.0

在此处输入图片说明

<com.google.android.material.chip.Chip
    style="@style/Widget.MaterialComponents.Chip.Action"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:text="Groceries"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

android android-view material-design android-chips material-components-android

7
推荐指数
1
解决办法
1726
查看次数