有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java数字选择器不能正确显示为设计器

我对Android Studio中的数字选择器控制有一些问题。当我运行应用程序时,控件在实际设备上没有正确显示。数字选择器没有灰色背景色,没有显示“+”/“-”按钮,它们都像是透明的

Android studio designer 这是XML

     <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent"
    安卓:background="#000000"
    >

    <ExpandableListView
        安卓:layout_width="wrap_content"
        安卓:layout_height="342dp"
        安卓:id="@+id/lvTranExp"
        安卓:layout_alignParentLeft="true"
        安卓:layout_alignParentStart="true"

        安卓:layout_above="@+id/numberPicker"
        安卓:layout_alignParentTop="true" />

    <LinearLayout
        安卓:orientation="horizontal"
        安卓:layout_width="match_parent"
        安卓:layout_height="match_parent"
        安卓:layout_alignParentBottom="true"
        安卓:layout_below="@+id/lvTranExp"
        安卓:layout_alignParentLeft="true"
        安卓:layout_alignParentStart="true"
        安卓:layout_alignParentRight="true"
        安卓:layout_alignParentEnd="true">

        <NumberPicker
            安卓:scaleX="0.5"
            安卓:scaleY="0.5"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:id="@+id/numberPickerStartDay"
            安卓:layout_below="@+id/lvTranExp"
            安卓:layout_toLeftOf="@+id/numberPickerStartDay"
            安卓:layout_toStartOf="@+id/numberPickerStartDay"
            安卓:solidColor="#da9c9c" />

        <NumberPicker
            安卓:scaleX="0.5"
            安卓:scaleY="0.5"
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:id="@+id/numberPickerStartMonth"
            安卓:layout_below="@+id/lvTranExp"
            安卓:layout_toRightOf="@+id/numberPickerStartDay"
            安卓:layout_toEndOf="@+id/numberPickerStartDay"
            安卓:solidColor="#895353" />

        <TextView
            安卓:layout_width="wrap_content"
            安卓:layout_height="wrap_content"
            安卓:textAppearance="?安卓:attr/textAppearanceSmall"
            安卓:text="Start date"

            安卓:textColor="#e9e97619"
            安卓:id="@+id/textView5"
            安卓:layout_below="@+id/lvTranExp"
       安卓:layout_alignBottom="@+id/numberPicker1"
            安卓:layout_marginLeft="40dp"

            安卓:layout_gravity="center" />
    </LinearLayout>


</RelativeLayout>

这是数字选择器的Java代码:

 View contentView = inflater.inflate(R.layout.activity_transactions, null);
    NumberPicker startDay = (NumberPicker)contentView.findViewById(R.id.numberPickerStartDay);
    NumberPicker startMonth = (NumberPicker)contentView.findViewById(R.id.numberPickerStartMonth);
    String []days = new String[31];
    for(int i =0;i<days.length;i++){
        days[i]=Integer.toString(i+1);
    }
    String []months = new String[12];
    for(int i =0;i<months.length;i++){
        months[i]=Integer.toString(i+1);
    }
    startDay.setMinValue(1);
    startDay.setMaxValue(31);
    startDay.setWrapSelectorWheel(false);
    startDay.setDisplayedValues(days);
    startDay.setValue(1);

    startMonth.setMinValue(1);
    startMonth.setMaxValue(12);
    startMonth.setWrapSelectorWheel(false);
    startMonth.setDisplayedValues(months);
    startMonth.setValue(1);

这是设备屏幕截图: enter image description here

提前谢谢


共 (0) 个答案