旋转器不可点击仅适用于三星Galaxy Note 4

时间:2016-06-23 20:29:57

标签: android android-layout android-spinner samsung-mobile

在一项活动中,我SpinnerViewPager相关联。我使用ButterKnife来监听使用@OnItemSelected注释选择的项目。我使用自定义布局和适配器来创建Spinner

public class BaseFragmentSpinnerAdapter extends ArrayAdapter<BaseFragment>
        implements ThemedSpinnerAdapter {

    private final ThemedSpinnerAdapter.Helper mDropDownHelper;

    public BaseFragmentSpinnerAdapter(Context context, List<BaseFragment> fragments) {
        this(context, fragments.toArray(new BaseFragment[fragments.size()]));
    }

    public BaseFragmentSpinnerAdapter(Context context, BaseFragment... fragments) {
        super(context, R.layout.view_spinner_item, fragments);
        mDropDownHelper = new ThemedSpinnerAdapter.Helper(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if(view == null {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_spinner_title, parent, false);
        }

        TextView titleView = (TextView) view.findViewById(R.id.title);
        titleView.setText(getItem(position).getTitle(getContext()));

        return view;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View view = convertView;

        if(view == null) {
            view = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_spinner_item, parent, false);
        }

        TextView textView = (TextView) view.findViewById(R.id.title);
        textView.setText(getItem(position).getTitle(getContext());

        return view;
    }

    @Override
    public Resources.Theme getDropDownViewTheme() {
        return mDropDownHelper.getDropDownViewTheme();
    }

    @Override
    public void setDropDownViewTheme(Resources.Theme theme) {
        mDropDownHelper.setDropDownViewTheme(theme);
    }

}

微调项目布局:

<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/title"
    android:layout_width="match_parent" android:layout_height="wrap_content"
    android:padding="@dimen/padding_standard" android:gravity="center_vertical"
    android:textColor="@color/selector_accent" android:textSize="@dimen/font_subhead"/>

最后,微调框项目布局的文本颜色的选择器:

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_checked="true" android:color="?attr/colorAccent"/>
    <item android:state_focused="true" android:color="?attr/colorAccent" />
    <item android:state_selected="true" android:color="?attr/colorAccent"/>
    <item android:state_pressed="true" android:color="?attr/colorAccent"/>
    <item android:state_activated="true" android:color="?attr/colorAccent" />
    <item android:color="?android:attr/textColorPrimary"/>
</selector>

此代码适用于我的两个测试设备(Nexus 5X和Nexus 7,均为6.0.1),以及我尝试过的所有仿真器(AVD Manager和Genymotion),范围从4.1到6.0。布局如下所示:

Android Spinner Working

但我的一位用户报告了运行5.1.1的三星Galaxy Note 4上的问题。未选择的项目文本显示为白色,并且项目不可点击:

Android Spinner Broken

有没有人遇到类似Galaxy Note 4(或其他设备)的问题?关于可能导致这种情况的任何想法?

0 个答案:

没有答案