在这里,我用了一些风格的“纺纱机”。为了设置微调器弹出窗口的高度,我使用了“列表弹出窗口”。对于更多的Android版本来说,它工作得很好。但不支持API 21和22(Android 5.0和5.1)。下面是我从中找到的代码
How to limit the height of Spinner drop down view in Android
Spinner newsSourceSpinner = (Spinner)findViewById(R.id.news_spinner);
try {
Field popup = Spinner.class.getDeclaredField("mPopup");
popup.setAccessible(true);
android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(newsSourceSpinner);
popupWindow.setHeight(250);
} catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
}
活动\u main.xml
<Spinner
android:id="@+id/news_spinner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
style="@style/Widget.AppCompat.Spinner.Underlined"
android:theme="@style/SpinnerStyle"
android:popupBackground="#80000000"
android:focusableInTouchMode="true"
android:focusable="true"/>
样式.xml
<style name="SpinnerStyle">
<item name="colorControlNormal">@color/colorWhite</item>
</style>