AutoCompleteTextView 不显示下拉菜单 - Android
AutoCompleteTextView not showing drop down menu - Android
我已经按照 material.io 构建了一个“暴露的下拉菜单”,但是下拉菜单没有显示。
我想实现这个:
Dropdown (screenshot from material.io)
但是,我目前得到的是:Failed dropdown
我不确定为什么我在将“android:inputType="none"" 添加到 AutoCompleteTextView 后还能在框中输入内容。
这就是我在片段中初始化适配器的方式:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_add, container, false);
// Initialise drop down list
ArrayAdapter<String> adapter = new ArrayAdapter<>(
getContext(),
R.layout.dropdown_menu_popup_item,
UNITS
);
AutoCompleteTextView unitsExposedDropdown = view.findViewById(R.id.unit_selection);
unitsExposedDropdown.setAdapter(adapter);
return view;
}
感谢您的帮助!
编辑:这是我用来构建公开下拉菜单的 link https://material.io/develop/android/components/menu
dont want to type in the box
那你为什么不使用弹出菜单看这个:
PopupMenu popup = new PopupMenu(youractivity.this, yourbutton);
//Inflate the pop up menu
popup.getMenuInflater().inflate(R.menu.popmenu, popup.getMenu());
//do something on click
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//do your work here
}
});
popup.show();//show it
要了解更多信息,请参阅此 https://developer.android.com/reference/android/widget/PopupMenu
我已经按照 material.io 构建了一个“暴露的下拉菜单”,但是下拉菜单没有显示。
我想实现这个: Dropdown (screenshot from material.io)
但是,我目前得到的是:Failed dropdown
我不确定为什么我在将“android:inputType="none"" 添加到 AutoCompleteTextView 后还能在框中输入内容。
这就是我在片段中初始化适配器的方式:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_add, container, false);
// Initialise drop down list
ArrayAdapter<String> adapter = new ArrayAdapter<>(
getContext(),
R.layout.dropdown_menu_popup_item,
UNITS
);
AutoCompleteTextView unitsExposedDropdown = view.findViewById(R.id.unit_selection);
unitsExposedDropdown.setAdapter(adapter);
return view;
}
感谢您的帮助!
编辑:这是我用来构建公开下拉菜单的 link https://material.io/develop/android/components/menu
dont want to type in the box
那你为什么不使用弹出菜单看这个:
PopupMenu popup = new PopupMenu(youractivity.this, yourbutton);
//Inflate the pop up menu
popup.getMenuInflater().inflate(R.menu.popmenu, popup.getMenu());
//do something on click
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
//do your work here
}
});
popup.show();//show it
要了解更多信息,请参阅此 https://developer.android.com/reference/android/widget/PopupMenu