【问题标题】:What is the name of this and how to code it in xml?它的名称是什么以及如何在 xml 中对其进行编码?
【发布时间】:2021-06-17 13:55:33
【问题描述】:

我正在通过各种方式对餐厅进行分类,并且使用了看起来很旧的溢出菜单。我想像给定的图片一样改变它。

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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"
    android:forceDarkAllowed="false"
    android:id="@+id/main_drawer_layout">
    <androidx.coordinatorlayout.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/main_coo_layout"
        >

        <com.google.android.material.appbar.AppBarLayout
            android:id="@+id/main_appbar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="0dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            >

            <androidx.appcompat.widget.Toolbar
                android:background="@color/tomato_red"
                android:id="@+id/main_toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:theme="@style/ThemeOverlay.AppCompat.Dark"
                android:elevation="0dp"
                app:layout_scrollFlags="scroll|enterAlways"
                app:title="All Restaurants"
                />

        </com.google.android.material.appbar.AppBarLayout>
        <FrameLayout
            android:id="@+id/main_frame_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </androidx.coordinatorlayout.widget.CoordinatorLayout>
    <com.google.android.material.navigation.NavigationView
        android:id="@+id/main_navigation_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:menu="@menu/main_menu"
        app:headerLayout="@layout/main_menu_header"
        android:layout_gravity="start"/>

</androidx.drawerlayout.widget.DrawerLayout>

要在此处进行哪些更改才能获得所需的结果。

【问题讨论】:

标签: android android-studio kotlin


【解决方案1】:

是芯片,你可以在你的应用程序中使用它来愚弄这个指令(直接来自 github 自述文件)

可通过 Google 的 Maven 存储库获得适用于 Android 的 Material Components。要使用它:

  1. 为您的应用打开 build.gradle 文件。

2.确保存储库部分包含 Google 的 Maven 存储库 google()。例如:

  allprojects {
    repositories {
      google()
      jcenter()
    }
  }

将库添加到依赖项部分:

  dependencies {
    // ...
    implementation 'com.google.android.material:material:<version>'
    // ...
  }

可以在这样的布局中添加芯片(.XML):

<com.google.android.material.chip.Chip
    android:id="@+id/chip"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/text"/>
 

可以像这样观察芯片的变化:

chip.setOnClickListener {
   // Responds to chip click
}

chip.setOnCloseIconClickListener {
    // Responds to chip's close icon click if one is present
}

chip.setOnCheckedChangeListener { chip, isChecked ->
    // Responds to chip checked/unchecked
}

【讨论】:

    猜你喜欢
    • 2022-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-18
    • 2012-02-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多