我想使用自定义结束图标从材料设计的 TextInputLayout 获取文本。
我试图这样做:
TextInputLayout textInputCustomEndIcon = findViewById(R.id.editText);
final TextInputEditText editText = new TextInputEditText(textInputCustomEndIcon.getContext());
textInputCustomEndIcon
.setEndIconOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (editText.getText() != null) {
String text = editText.getText().toString();
Log.i("MainActivity", "setEndIconOnClickListener:"+ text);
}
}
});
Run Code Online (Sandbox Code Playgroud)
但我得到一个空文本,不是空而是空!!
android material-design android-textinputlayout android-textinputedittext
我正在使用 Material 设计库制作圆形的 editText,我能够做到这一点,但现在我希望它看起来更小,我使用了密集的 textField 样式,但我仍然希望视图的高度更小比起那个来说。问题是浮动 Label 标签,我没有为 textField 设置提示,但 Label 标签仍然占用一些空白空间。
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:endIconMode="custom"
app:endIconDrawable="@drawable/ic_speaker_24dp"
app:layout_constraintBottom_toBottomOf="@+id/topBar_view"
app:layout_constraintEnd_toEndOf="@+id/topBar_view"
app:layout_constraintStart_toEndOf="@+id/separater_line"
app:layout_constraintTop_toTopOf="parent"
app:boxCornerRadiusTopStart="20dp"
app:boxCornerRadiusTopEnd="20dp"
app:boxCornerRadiusBottomStart="20dp"
app:boxCornerRadiusBottomEnd="20dp">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我只希望 textField 看起来像 chrome url 搜索栏,苗条,键入时提示消失,而不是浮动标签。
编辑:我尝试了该app:hintEnabled="false"属性,但仍有一个空白空间
android material-design android-textinputlayout material-components material-components-android
我认为通过存储base64字符串图像,它会快很多,因为你不需要上传也不需要下载任何东西,而且字符串比实际图像占用更少的存储空间!
我对此进行了搜索,但我不明白为什么,但每个人都说这将是一个糟糕的决定,与我所说的一切相反,我不明白为什么?