如何修复android菜单项中微调框的奇怪显示?

时间:2019-05-08 04:32:43

标签: java android spinner android-5.1.1-lollipop

此问题仅出现在android 5.1中。微调器标题和三角形之间非常奇怪的,无形的线条。但是我使用的代码非常简单和标准。

enter image description here

某些代码:

    @Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.trip_driver, menu);
    this.menu = menu;
    textInOut = menu.findItem(R.id.text_in_out);

    MenuItem item = menu.findItem(R.id.menu_spinner);
    Spinner spinner = (Spinner) item.getActionView();
    spinner.setMinimumWidth(100);

    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.menu_items, R.layout.custom_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                switch (position){
                    case 0: viewPager.setCurrentItem(0); break;
                    case 1: viewPager.setCurrentItem(1); break;
                    case 2: viewPager.setCurrentItem(2); break;
                    case 3: viewPager.setCurrentItem(3); break;
                    default: viewPager.setCurrentItem(0); break;
                }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

和自定义微调代码:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    android:singleLine="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:textAlignment="inherit"
    android:textColor="@color/white"/>

绝对不知道为什么会这样

0 个答案:

没有答案