You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何确认截图对应的Android控件在Android Studio中的名称

问题

我是Android开发新手,若有表述不周之处还请见谅...
请问图中所示控件在Android Studio中的对应名称是什么?我此前尝试通过谷歌检索相关内容,但始终没能找到准确结果。

待确认控件截图


回答

这个是Material Design组件库提供的暴露式下拉菜单(Exposed Dropdown Menu),不是Android SDK原生的独立基础控件,很多人搜不到是因为它是组合实现的控件,不存在单一的对应控件类名:

  • 外层用TextInputLayout作为容器,必须指定ExposedDropdownMenu对应的样式
  • 内部嵌套AutoCompleteTextView(推荐用Material库封装的MaterialAutoCompleteTextView)承载下拉选择逻辑
  • 控件默认自带下拉箭头,点击输入区域弹出选项列表,样式比原生老旧的Spinner更符合现代UI规范

使用前提:

  • 在模块的build.gradle中引入Material Components依赖
  • 项目App主题继承自MaterialComponents系列主题,否则控件会出现样式错乱

基础布局写法参考:

<com.google.android.material.textfield.TextInputLayout
    style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="请选择">

    <com.google.android.material.textfield.MaterialAutoCompleteTextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="none"
        android:focusable="false"/>

</com.google.android.material.textfield.TextInputLayout>

给控件绑定下拉选项的逻辑和普通AutoCompleteTextView完全一致,设置对应ArrayAdapter即可。


内容的提问来源于stack exchange,提问作者Learn2Code

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.27 01:42:18