gpt4 book ai didi

android - RTL 设备上的日期格式发生变化?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:55:56 25 4
gpt4 key购买 nike

我有一个日期字段,在 LTR 设备 (android 7.1.1) 上显示得很好
问题是在 RTL 设备上,日期字段内容是镜像的

因此在美国设备上日期将正常显示:03/14/2019
在 RTL android 设备上,日期将显示如下:2019/14/03

保存值的 TextView 的代码:

    <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/inspect_date"
android:textSize="18sp" />

<com.xerox.printerinspection.controls.DateEditText
android:id="@+id/edit_inspect_date"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/lightGray"
android:paddingStart="4dp"
android:paddingEnd="4dp"
android:drawableEnd="@android:drawable/ic_menu_my_calendar" />
</LinearLayout>

我是这样设置日期的:

   Date currentDate = Calendar.getInstance().getTime();
inspectionDateEdit.setDate(currentDate);

解决此问题的正确方法是什么?

更新

父级 fragment_detail.xml 标签如下所示:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/lightGray"
android:textDirection="locale"
tools:context="com.xerox.MainActivity">

最佳答案

由于父级的 android:textDirection="locale" 属性(甚至可能是默认值,当在Manifest.xml - 因此可以省略),必须为嵌套子节点定义文本方向 - 因此它不会继承父节点的值;当在 LTR 设备上强制使用 RTL 布局时,这至少适用于 EditText:

<androidx.appcompat.widget.AppCompatEditText
android:id="@+id/edit_inspect_date"
android:text="@string/edit_inspect_date"
android:textDirection="ltr"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

screenshot

可能 android:drawableEnd 应该是 android:drawableRight,这样它就不会受到影响(这取决于是否打算将其翻转到另一边,无论是否)。

关于android - RTL 设备上的日期格式发生变化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55309814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com