我试图将我的 AutoCompleteTextView
的下拉高度设置为屏幕底部以上 60dp。
displayMetrics = new DisplayMetrics();
WindowManager windowmanager = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
windowmanager.getDefaultDisplay().getMetrics(displayMetrics);
int height = Math.round(displayMetrics.heightPixels / displayMetrics.density - 60);
edtSeach.setDropDownHeight(height);
这适用于运行 Android 7.0 的华为 P9 Lite。
但是,当我尝试运行 Android 6.0 的模拟器时,它无法正常工作。
如何解决?
最佳答案
我通过实现扩展 AppCompatAutoCompleteTextView
的自定义类自行解决了这个问题。
public void showDropDown() {
Rect displayFrame = new Rect();
getWindowVisibleDisplayFrame(displayFrame);
int[] locationOnScreen = new int[2];
getLocationOnScreen(locationOnScreen);
int bottom = locationOnScreen[1] + getHeight();
int availableHeightBelow = displayFrame.bottom - bottom;
Resources r = getResources();
int bottomHeight = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, r.getDisplayMetrics()));
int downHeight = availableHeightBelow - bottomHeight;
setDropDownHeight(downHeight);
super.showDropDown();
}
关于android - 将 AutoCompleteTextView 下拉高度设置为底部上方 60dp,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49335670/