Android:无法向下滚动微调器

Android:无法向下滚动微调器,android,textview,android-spinner,android-theme,android-styles,Android,Textview,Android Spinner,Android Theme,Android Styles,在这里,我使用带有“android:theme”的“微调器”来更改下划线的颜色和微调器的下拉箭头。对于微调器的“获取基本样式”和微调器弹出背景颜色的“android:PopubBackground”,也可以使用“样式”。最后,我使用“spinner\u item.xml”来更改微调器的文本颜色。完成以上所有操作后,微调器不会向上或向下滚动。下面是我的代码 @styles/styles.xml <style name="SpinnerStyle"> <item name="

在这里,我使用带有“android:theme”的“微调器”来更改下划线的颜色和微调器的下拉箭头。对于微调器的“获取基本样式”和微调器弹出背景颜色的“android:PopubBackground”,也可以使用“样式”。最后,我使用“spinner\u item.xml”来更改微调器的文本颜色。完成以上所有操作后,微调器不会向上或向下滚动。下面是我的代码

@styles/styles.xml

<style name="SpinnerStyle">
   <item name="colorControlNormal">@color/colorWhite</item>
</style>
<Spinner
            android:id="@+id/news_source_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:theme="@style/SpinnerStyle"
            android:popupBackground="#80000000"
            android:focusableInTouchMode="true"
            android:focusable="true"/>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="13sp"
    android:gravity="left"
    android:padding="5dip"
    android:textColor="@color/colorWhite"/>

@彩色/彩色白色
activity.xml

<style name="SpinnerStyle">
   <item name="colorControlNormal">@color/colorWhite</item>
</style>
<Spinner
            android:id="@+id/news_source_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:theme="@style/SpinnerStyle"
            android:popupBackground="#80000000"
            android:focusableInTouchMode="true"
            android:focusable="true"/>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="13sp"
    android:gravity="left"
    android:padding="5dip"
    android:textColor="@color/colorWhite"/>

@layout/spinner\u item.xml

<style name="SpinnerStyle">
   <item name="colorControlNormal">@color/colorWhite</item>
</style>
<Spinner
            android:id="@+id/news_source_spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            style="@style/Widget.AppCompat.Spinner.Underlined"
            android:theme="@style/SpinnerStyle"
            android:popupBackground="#80000000"
            android:focusableInTouchMode="true"
            android:focusable="true"/>
<TextView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="13sp"
    android:gravity="left"
    android:padding="5dip"
    android:textColor="@color/colorWhite"/>

MainActivity.java

@BindView(R.id.news_source_spinner)
        Spinner newsSourceSpinner;

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    ButterKnife.bind(this);

    spinnerAdapter = new ArrayAdapter<String>(context,R.layout.spinner_item, itemList);
    newsSourceSpinner.setAdapter(spinnerAdapter);

}
@BindView(R.id.news\u source\u微调器)
微调器新闻源微调器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
把(这个)绑起来;
spinnerAdapter=新的ArrayAdapter(上下文,R.layout.spinner\u项,项列表);
setAdapter(spinnerAdapter);
}

最后,我用以下代码解决了我的问题,为微调器弹出窗口设置了固定高度

Spinner spinner = (Spinner) findViewById(R.id.spinner);
    try {
        Field popup = Spinner.class.getDeclaredField("mPopup");
        popup.setAccessible(true);

        // Get private mPopup member variable and try cast to ListPopupWindow
        android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);

        // Set popupWindow height to 500px
        popupWindow.setHeight(500);
    }
    catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
        // silently fail...
    }

最后,我用以下代码解决了我的问题,为微调器弹出窗口设置了固定高度

Spinner spinner = (Spinner) findViewById(R.id.spinner);
    try {
        Field popup = Spinner.class.getDeclaredField("mPopup");
        popup.setAccessible(true);

        // Get private mPopup member variable and try cast to ListPopupWindow
        android.widget.ListPopupWindow popupWindow = (android.widget.ListPopupWindow) popup.get(spinner);

        // Set popupWindow height to 500px
        popupWindow.setHeight(500);
    }
    catch (NoClassDefFoundError | ClassCastException | NoSuchFieldException | IllegalAccessException e) {
        // silently fail...
    }

谢谢,老兄,设定一个固定的高度对我也很有用。奇怪的一个,因为它在一些机器人身上工作得很好,而不是其他的汉克斯兄弟,设定一个固定的高度对我也很有效。奇怪的一个,因为它在一些机器人身上工作得很好,而在其他机器人身上没有