简体   繁体   English

如何使我的自定义微调器像默认微调器?

[英]How to Make my custom spinner like default spinner?

So, i have a data which is from my table so i'm using adapter. 所以,我有一个数据来自我的表,所以我使用适配器。 Here is how i set it up in my adapter 这是我在我的适配器中设置它的方式

public View getView(int position, View convertView, ViewGroup parent) {
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View row = inflater.inflate(R.layout.list_item, parent,false);
    // get your views here and set values to them

    TextView ItemCodetextview = (TextView) row.findViewById(R.id.itemcode);
    TextView ItemNametextview = (TextView) row.findViewById(R.id.itemname);

    GenerateItemdoModel current = dataModels.get(position);

    ItemCodetextview.setText(current.getItemCode());
    ItemNametextview.setText(current.getItemName());

    return row;
}

list_item 项目清单

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_marginTop="20sp"
    android:layout_marginRight="20sp"
    android:layout_height="wrap_content">

    <TextView
        android:layout_width="wrap_content"
        android:id="@+id/itemcode"
        android:textSize="12sp"
        android:text="1"
        android:textStyle="bold"
        android:layout_marginLeft="20sp"
        android:ellipsize="marquee"
        android:layout_height="wrap_content" />

    <TextView
        android:layout_width="wrap_content"
        android:id="@+id/itemname"
        android:layout_marginLeft="20sp"
        android:text="2"
        android:textSize="12sp"

        android:ellipsize="marquee"
        android:textStyle="bold"

        android:layout_height="wrap_content" />

</LinearLayout>

spinner in my xml 我的xml中的微调器

<LinearLayout
    android:layout_marginLeft="20sp"
    android:layout_width="fill_parent"
    android:orientation="horizontal"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:text="Item Code"
        android:textStyle="bold"
        android:layout_gravity="center"
        android:gravity="center"
        android:textSize="12sp"
        android:layout_height="match_parent" />

    <Spinner
        android:id="@+id/itemcodeval"
        android:layout_width="match_parent"
        android:textStyle="bold"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginStart="40sp"/>

    <EditText
        android:id="@+id/valueitemcde"
        android:layout_width="wrap_content"
        android:visibility="gone"
        android:layout_height="wrap_content" />

</LinearLayout>

my default spinner (without adapter) 我的默认微调器(没有适配器)

<LinearLayout
    android:layout_marginTop="30sp"
    android:layout_marginLeft="20sp"
    android:orientation="horizontal"

    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:text="Tipe Rijek"
        android:layout_gravity="center"
        android:textStyle="bold"
        android:gravity="center"
        android:textSize="12sp"
        android:layout_height="match_parent" />

    <Spinner
        android:id="@+id/tipeval"
        android:layout_width="match_parent"
        android:textStyle="bold"
        android:layout_height="wrap_content"
        android:layout_marginLeft="40sp"
        android:layout_marginStart="40sp"
        />
    <EditText
        android:id="@+id/valuetipe"
        android:layout_width="wrap_content"
        android:visibility="gone"
        android:textSize="12sp"
        android:layout_height="wrap_content" /> </LinearLayout>

here is the screenshot of custom spinner with adapter 这是带适配器的自定义微调器的屏幕截图

在此输入图像描述

and here is the default spinner 这是默认的微调器

在此输入图像描述

so, my question is how can i make my custom spinner looks like the default spinner ? 所以,我的问题是如何使我的自定义微调器看起来像默认微调器? thanks in advance and sorry for my english 提前谢谢,对不起我的英语

Use this in you spinner 在你的微调器中使用它

style="@android:style/Widget.Holo.Light.Spinner"

Reference : https://developer.android.com/guide/topics/ui/look-and-feel/themes.html 参考: https//developer.android.com/guide/topics/ui/look-and-feel/themes.html

(or) (要么)

use this 用这个

Adding a small attribute as android:spinnerMode="dialog" 添加一个小属性android:spinnerMode="dialog"

In list_item.xml : list_item.xml中

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:paddingTop="10dp"
    android:paddingBottom="10dp"
    android:paddingLeft="5dp"
    android:layout_height="wrap_content">

Add padding in main layout in item layout. 在项目布局中的主布局中添加填充。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM