Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 带有默认向下箭头的自定义微调器_Android_Android Layout_Spinner_Android Spinner - Fatal编程技术网

Android 带有默认向下箭头的自定义微调器

Android 带有默认向下箭头的自定义微调器,android,android-layout,spinner,android-spinner,Android,Android Layout,Spinner,Android Spinner,我有一个微调器的自定义布局。其所选和下拉列表项的背景颜色将根据用户需求而变化。所以我会根据他们的价值观而改变。。到现在为止,一直都还不错。但问题是,因为我使用自定义布局或更改背景色,所以没有箭头显示它是微调器。当我从布局中添加箭头时,所有偶数下拉列表都带有该箭头。我可以通过为下拉项将arrow的背景设置为null来操作它,但这不是一个好方法,也不总是有效的。那么,如何在不使用微调器样式的情况下使用自定义微调器显示微调器默认箭头呢。别忘了我正在改变每件物品的背景 这是我的自定义_spinner.x

我有一个微调器的自定义布局。其所选和下拉列表项的背景颜色将根据用户需求而变化。所以我会根据他们的价值观而改变。。到现在为止,一直都还不错。但问题是,因为我使用自定义布局或更改背景色,所以没有箭头显示它是微调器。当我从布局中添加箭头时,所有偶数下拉列表都带有该箭头。我可以通过为下拉项将arrow的背景设置为null来操作它,但这不是一个好方法,也不总是有效的。那么,如何在不使用微调器样式的情况下使用自定义微调器显示微调器默认箭头呢。别忘了我正在改变每件物品的背景

这是我的自定义_spinner.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:weightSum="6" android:id="@+id/spinnerMainLayout"
android:layout_height="wrap_content">

<LinearLayout
    android:orientation="horizontal" android:layout_width="match_parent"
    android:weightSum="14"
    android:layout_height="wrap_content">
<TextView
    android:layout_width="0dp"  android:layout_marginTop="8dp"
    android:layout_height="wrap_content" android:layout_marginLeft="10dp"
    android:text="New Text" android:textSize="19sp" android:layout_weight="5"
    android:layout_gravity="center" android:layout_marginBottom="8dp"
    android:gravity="center" android:layout_marginRight="4dp"
    android:id="@+id/type" android:typeface="serif"/>

<View
    android:layout_width="1dp"  android:layout_marginLeft="8dp"  android:layout_marginTop="4dp"
    android:layout_height="match_parent" android:layout_marginBottom="4dp"
    android:background="#666666" />

<TextView
    android:layout_width="0dp"  android:layout_height="wrap_content"
    android:layout_marginTop="8dp" android:layout_weight="9"
    android:typeface="serif" android:maxLines="3" android:minLines="2"
    android:layout_gravity="center" android:layout_marginBottom="8dp"
    android:layout_marginLeft="10dp" android:layout_marginRight="5dp"
    android:text="sd" android:textSize="18sp" android:gravity="center_vertical"
    android:id="@+id/history" />

    </LinearLayout>


</LinearLayout>
这是我的自定义微调器类

class CustomSpinner extends ArrayAdapter<String>  {

    private String[] fixStrs = new String[]{"Definition","Result","Error"};

    public CustomSpinner(Context ctx, int txtViewResourceId, String[] objects) {
        super(ctx, txtViewResourceId, objects);
        //fixStrs = objects;
    }

    @Override public View getDropDownView(int position, View cnvtView, ViewGroup prnt) {
        return getCustomView(position, cnvtView, prnt);
    }

    @Override public View getView(int pos, View cnvtView, ViewGroup prnt) {
        return getCustomView(pos, cnvtView, prnt);
    }

    public View getCustomView(int position, View convertView, ViewGroup parent) {

        LayoutInflater inflater = getLayoutInflater();
        View mySpinner = inflater.inflate(R.layout.custom_spinner, parent, false);

        /*LinearLayout spinnerMain = (LinearLayout) mySpinner.findViewById(R.id.spinnerMainLayout);
        spinnerMain.setBackgroundColor(Color.parseColor(colors[0]));*/

        TextView fixText = (TextView) mySpinner.findViewById(R.id.type);
        fixText.setText(fixStrs[position]);
        fixText.setTextColor(Color.parseColor(colors[1]));

        TextView historyText = (TextView) mySpinner.findViewById(R.id.history);
        historyText.setText(history[position]);
        historyText.setTextColor(Color.parseColor(colors[1]));

        return mySpinner;
    }

}

为微调器下拉列表创建一个不同的布局,并将其传递给ArrayAdapter的方法,然后您必须在适配器的构造函数调用中指定此布局中textview的id

您能更具体地描述一下吗?