- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
EDIT 我刚刚尝试了一个没有 TextInputLayout
的 EditText
并且它按预期工作。所以问题一定出在 TextInputLayout
的新变化上。
我已经使用自定义 EditText
类作为 TextInputLayout
的子级大约一个月了。当用户键入时,x
将出现在 drawableRight
字段中。我已经成功地显示了 drawableLeft
、drawableTop
和 drawableBottom
的图像,但是设置 drawableRight
为我提供了一个空白。 注意:单击 X
应按预期工作的空白处,文本将被清除。
第一张图片是它原来的样子:
自从升级到 support-v4:24.2.0
之后,功能就被破坏了。它现在将“x”放置在带有 drawableBottom
的可绘制集应该出现的位置。第二张图片显示了新行为:
<android.support.design.widget.TextInputLayout
android:id="@+id/til_delivery_info_state"
android:hint="@string/state_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/large_margin"
android:layout_marginRight="@dimen/large_margin">
<com.example.ui.edittexts.ClearableEditText
android:id="@+id/et_state"
android:inputType="textCapWords|text|textNoSuggestions"
android:nextFocusDown="@+id/et_di_zip_code"
android:text="@={deliveryViewModel.state}"
android:gravity="center_vertical|left"
android:singleLine="true"
android:textSize="@dimen/text_size"/>
</android.support.design.widget.TextInputLayout>
final Drawable drawable = ContextCompat.getDrawable(context, R.drawable.ic_clear_text_gray_x);
final Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
mClearTextIcon.setBounds(0, 0, mClearTextIcon.getIntrinsicWidth(), mClearTextIcon.getIntrinsicHeight());
mClearTextIcon.setVisible(true, false);
final Drawable[] compoundDrawables = getCompoundDrawables();
setCompoundDrawablesWithIntrinsicBounds(
compoundDrawables[0],
compoundDrawables[1],
visible ? mClearTextIcon : null,
compoundDrawables[3]);
最佳答案
支持库 24.2.1
的新版本已发布,此问题已标记为已修复。根据变更日志
Fixed issues:
TextInputLayout overrides right compound drawable. (AOSP issue 220728)
警告 1这个答案将破坏这个新的密码可见性切换功能。
警告 2此答案可能会在更新支持库后导致意外行为(假设他们会解决此问题)。
看起来 TextInputLayout
把事情搞砸了,特别是 updatePasswordToggleView
方法中的这些行。
final Drawable[] compounds = TextViewCompat.getCompoundDrawablesRelative(mEditText);
TextViewCompat.setCompoundDrawablesRelative(mEditText, compounds[0], compounds[1], mPasswordToggleDummyDrawable, compounds[2]);
如您所见,它将 mPasswordToggleDummyDrawable
设置为 right
可绘制对象,然后设置 compounds[2]
(这是您的自定义可绘制对象,您想成为其中之一)作为可绘制的 bottom
。
updatePasswordToggleView
方法在 onMeasure
方法中调用。可能的解决方法是创建自定义 TextInputEditText
并覆盖它的 onMeasure
方法。我们称它为 PassFixTextInputEditText
public class PassFixTextInputEditText extends TextInputEditText {
public PassFixTextInputEditText(final Context context) {
super(context);
}
public PassFixTextInputEditText(final Context context, final AttributeSet attrs) {
super(context, attrs);
}
public PassFixTextInputEditText(final Context context, final AttributeSet attrs, final int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
Drawable[] drawables = getCompoundDrawables();
setCompoundDrawables(drawables[0], drawables[1], drawables[3], null);
}
}
然后像这样使用它
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:errorEnabled="true">
<com.kamilzych.temp.PassFixTextInputEditText
android:id="@+id/textInputEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLength="23"/>
</android.support.design.widget.TextInputLayout>
(不要忘记更改包名称)
如您所见,在 TextInputLayout
将自定义可绘制对象设置为底部可绘制对象后,我们将其设置为右侧。
关于android - 新的 Password Visibility Toggle 是否破坏了 EditTexts 的现有 drawableRight?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39132192/
这个问题已经有答案了: Where has fn.toggle( handler(eventObject), handler(eventObject)...) gone? (4 个回答) 已关闭10
有没有直接的使用方法--toggle和 --no-toggle使用 Python 的 argparse 标记? 现在我正在使用类似于以下内容的东西: import argparse parser =
我正在尝试实现 jquery UI 切换功能。 这是我目前所拥有的: http://jsfiddle.net/PauWy/470/ 我试图做到这一点,当我点击 Item1 时,会出现“+”和“-”,我
现在 toggle(...) 是 deprecated in jQuery 1.8然后removed in jQuery 1.9 在常规中可以使用什么(除了使用 jQuery 迁移脚本)来代替具有相同
我在使用 bootstrap 的切换功能时遇到问题。 这个想法是让一个复选框(引导切换)打开或关闭第二个复选框(引导切换)。遗憾的是,它尚未在网页上运行。我注意到,通过删除“data-toggle='
我有一些 DIV,我正在使用 JQuery 使用 toggle() 函数来隐藏和显示它们。这一直运行良好。 但我只是认识到其中一些 DIV 之间的一些关系,这使我可以将其中一些 DIV 分组到一个类中
我想要三个 SwiftUI 切换开关,如果一个打开,另外两个关闭。 使用 UIKit 执行此类操作的旧方法是 didSet{},这不是 SwiftUI 的正确方法。我不知道是否有必要深入研究Combi
我想做的是:当达到一定数量的页面滑动时,使网站的顶部栏向下切换。即,当用户向下滑动 328px 时,顶部栏向下滑动并固定在顶部。 问题是当用户向下滑动到328px的时候,top bar div就开始上
上下文 我正在使用 Bootstrap 主题,现在我注意到,当主题更新到 Bootstrap 5 时,所有 data-toggle 属性都被替换为 data-bs-toggle (除了一个,哪个元素仍
我有一个来自 Bootstrap 示例的“标准”测试导航栏,但是使用 active_links gem导航栏 => 品牌 - 关于 - 第 1 页 - 第 2 页 - 页面(第 3 页 - 第 4 页
我只是无法理解 Eclipse 中菜单的 Run 按钮下的两个选项。通常断点不是指一行吗?我意识到可能存在这种情况: if (x >= 0 && x = 0 && y < 4) source
如果有任何反馈或见解可以帮助我解决我面临的最后一个问题,我将不胜感激。我的代码很庞大。 我有 4 个开关。打开时的每个切换都会导致标签增加 1。当我关闭并重新打开应用程序时,我还设法保存了切换位置和标
我目前正在开发一个侧边栏菜单,在该菜单中我切换类别上的“选定”类别,该类别的类别名称为“sidebar-category”。 使用 jQuery,我可以轻松实现我想要的目标:切换“选定”类后(如果我单
我正在尝试玩周围的游戏,但我对 jquery 完全是新手!所以我确实需要一些帮助:) $(function() { $('#switch').on('click', function(
所以我需要下面的当前脚本,以便能够切换。 目前,该脚本仅在按住 F8 键时起作用...这违背了 afk 脚本的要点。哈哈 无论如何,这是脚本: $F8:: Loop { if not Get
在创建 jQuery 下拉菜单时,我遇到了一个最奇怪的问题 - 已隐藏的元素仍然影响页面。为什么会发生这种情况,我该如何解决?它通过阻止按钮的一部分来影响功能,迫使人们从未阻止的部分调用该功能。例如;
我有一个 Logo ,当单击菜单时,字母 T 和 H 以及字母 animatie 彼此相距约 400px。当他们制作动画时,导航会出现:eas-in,但是当我再次单击汉堡菜单时,我希望导航以相同的动画
我正在尝试为“事件”CSS 类切换“禁用”,以使某些 SVG 的填充属性在单击时发生变化。 我能够正确更改第一个元素,但是当尝试对第二个和第三个 SVG 进行相同更改时,它会更改第一个 div 中第一
我有一个小的下拉列表,其中包含从 0 到 4 的数字(我可以添加更多),例如数字 4 是 4 年的数据。如果我选择 4,我会得到 4 行日期选择器,供用户选择开始和结束日期。 它使用 for 循环,并
我有几个 powershell 函数,可以执行诸如检查程序是否打开然后关闭之类的操作。或者,如果程序关闭,该函数将打开它。这些函数被恰本地命名为Toggle-Something。我在 Windows
我是一名优秀的程序员,十分优秀!