android - setText 不适用于自定义 Edittext

标签 android android-edittext settext

我正在使用我从 github 上找到的一个很好的 Material 设计编辑文本:https://github.com/rengwuxian/MaterialEditText

并将依赖部分更新为:

dependencies {
   compile 'com.rengwuxian.materialedittext:library:2.0.3'
}

edittext xml定义如下:

    <com.rengwuxian.materialedittext.MaterialEditText
        android:id="@+id/device_file_location_value"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_file_location"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:enabled="true"
        android:focusable="false"
        android:clickable="true"
        app:met_floatingLabel="normal"
        app:met_floatingLabelText="@string/file_location"
        app:met_singleLineEllipsis="true"
        app:met_baseColor="#FCFBE3"
        app:met_primaryColor="#FCFBE3"/>

所以我希望通过浏览文件系统以编程方式填充编辑文本的值。所以 edittext 是可点击但不可聚焦的,因此用户无法编辑接收到的文件的路径。现在这个 (device_file_location_value) 编辑文本由从其他 fragment (实现文件浏览器的 fragment )接收的值更新,并在其 fragment 的 onCreateView 中更新如下:

        Bundle bundle = getArguments();
        String filePath = bundle.getString(FileBrowserFragment.PARAM_FILE_PATH);
        if (filePath != null) {
            filePathValue.setText(filePath);
            bundle.remove(FileBrowserFragment.PARAM_FILE_PATH);
        }

不知何故,这并没有更新 UI 上的文本。我也尝试过使用 filePathValue.invalidate() 但这也没有帮助。

感谢任何帮助。

最佳答案

这样试试。

filePathValue.post(new Runnable() {
                @Override
                public void run() {
                    filePathValue.setText(filePath);
                }
            })

关于android - setText 不适用于自定义 Edittext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34949137/

相关文章:

android - Kindle 的 Android 应用程序如何处理字典查找的点击

android - 提示文本在 Android 2.3 版本中看不到,但它适用于 4.1

android - 为什么我们需要在Android Studio中连接字符串之前添加@SuppressLint ("SetTextI18n")注解

java - Android:为什么后续代码阻止 TextView 的 .setText() 工作

java - Android studio 奇怪警告

android - 抽屉导航 Activity (点击事件)

android - 文本输入的 HTML 5 模式验证不适用于带有 iphone 的 safari 或 firefox

android - 如何使用Android mapview在模拟器中获取当前位置(纬度和经度)?

android - 获取安卓应用的启动器Activity名称

c# - android 中的 TextInputEditText 没有获得焦点