Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

时间格式年月日、月日年顺序修改;语言国际化(英文、繁体...) #1009

Open
A-10ng opened this issue May 9, 2022 · 0 comments

Comments

@A-10ng
Copy link

A-10ng commented May 9, 2022

在海外的项目中,由于用户的习惯不同,在时间选择的格式上常常需要用到“ 月 日 年 ”这样的顺序和月份的本地化,但是博主大佬提供的自定义方法只有年月日时分的固定顺序以及显示隐藏,并且月份也只能是数字,以下是一些灵性的解决方法,欢迎大家继续补充!!!

1.时间格式的顺序修改

在 TimePickerBuilder 的 TimePickerView 中,我们可以发现有一份可以自定义的布局,里面通常包括五个WheelView,分别显示年月日时分,所以如果想要调整时间格式的顺序,直接修改布局即可!这里贴一份自己项目中的布局:
`

<data>

</data>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="226dp"
    android:background="@drawable/shape_popup_round_bg"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/iv_back"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tan_back"
        android:paddingTop="10dp"
        android:paddingLeft="10dp"/>
    <ImageView
        android:id="@+id/iv_ok"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/tan_ok"
        android:paddingTop="10dp"
        android:paddingLeft="10dp"
        android:layout_alignParentRight="true"
        android:paddingRight="10dp"
        android:layout_alignTop="@+id/iv_back"/>

    <TextView
        android:visibility="invisible"
        android:id="@+id/tv_gongli"
        android:layout_width="80dp"
        android:layout_height="30dp"
        android:text="@string/calendar"
        android:textColor="@color/white"
        android:textSize="14sp"
        android:background="@drawable/shape_date_popupwin"
        android:gravity="center"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"/>

    <RelativeLayout
        android:id="@+id/ll_date_picker"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/tv_gongli"
        android:layout_marginTop="20dp"
        android:paddingLeft="27.5dp"
        android:paddingRight="27.5dp">
        <LinearLayout
            android:id="@+id/timepicker"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/shape_date_bg"
            android:gravity="center"
            android:minHeight="150dp"
            android:orientation="horizontal"
            android:paddingLeft="10dp"
            android:paddingRight="10dp">

            <com.xxx.astrology.customview.EnglishMonthWheelView
                android:id="@+id/month"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
            <View
                android:layout_width="@dimen/divider_height"
                android:layout_height="match_parent"
                android:background="#FFEFEFEF"/>

            <com.contrarywind.view.WheelView
                android:id="@+id/day"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
            <View
                android:layout_width="@dimen/divider_height"
                android:layout_height="match_parent"
                android:background="#FFEFEFEF"/>

            <com.contrarywind.view.WheelView
                android:id="@+id/year"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="0.96" />
            <View
                android:layout_width="@dimen/divider_height"
                android:layout_height="match_parent"
                android:background="#FFEFEFEF"/>

            <com.contrarywind.view.WheelView
                android:id="@+id/hour"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
            <View
                android:visibility="gone"
                android:layout_width="@dimen/divider_height"
                android:layout_height="match_parent"
                android:background="#FFEFEFEF"/>

            <com.contrarywind.view.WheelView
                android:id="@+id/min"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
            <View
                android:visibility="gone"
                android:layout_width="@dimen/divider_height"
                android:layout_height="match_parent"
                android:background="#FFEFEFEF"/>

            <com.contrarywind.view.WheelView
                android:id="@+id/second"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1" />
        </LinearLayout>
        <ImageView
            android:layout_width="7dp"
            android:layout_height="11dp"
            android:src="@drawable/shape_triangle_select"
            android:layout_centerVertical="true"/>

    </RelativeLayout>

</RelativeLayout>
`

2.语言国际化

实现思路主要是修改 WheelView 类的 getContentText 方法,根据阿拉伯数字返回我们所需的文字即可。但是 WheelView 类的 getContentText 方法是私有,我们只能手动下载下来该方法的可见性。

上面的 EnglishMonthWheelView 参考了issue #575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant