我有一个包含在TextInputLayout中的EditText。我希望在EditText下方显示错误,但对齐到屏幕的右侧。
我的XML是这个:
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_email"
style="@style/forgot_pass_text_inputlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_enter_email_message"
android:layout_marginTop="@dimen/email_padding_top"
android:hintTextAppearance="@{forgotPasswordVM.hintTextAppearance}"
android:theme="@style/forgot_pass_til_state"
app:error="@{forgotPasswordVM.email.textInputError}">
<EditText
android:id="@+id/actv_email"
style="@style/forgot_pass_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_address"
android:imeActionId="@+id/btn_submit"
android:imeOptions="actionSend"
android:inputType="textEmailAddress"
android:maxLines="1"
android:onEditorAction="@{forgotPasswordVM.onEditorAction}"
android:singleLine="true"
app:binding="@{forgotPasswordVM.email.text}" />
</android.support.design.widget.TextInputLayout>
我正在使用数据绑定。
我尝试在EditText和TextInputLayout上设置android:gravity="right"
和android:layout_gravity="right"
,但都无法达到我想要的效果。
我尝试在主题和样式中设置右对齐,但都没有影响错误文本的位置。
我尝试在app:errorTextAppearance="@style/right_error"
中应用的样式中设置右对齐,但仍然不起作用。
我还尝试通过使用AlignmentSpan的SpannableStringBuilder进行编程以将错误消息向右移动,具体可以参考这个链接。但是这对我也没有用。
我不知道还有什么其他尝试的方法,请提供建议。
TextView
错误,并在其上调用setGravity(Gravity.RIGHT)
。虽然我没有测试过,但如果我没记错的话,错误的TextView
具有match_parent
宽度,因此它应该按照你描述的对齐其文本。 - Mike M.