我正在使用最新版本的android材料设计库(1.2.0-alpha05)。我在 TextInputLayout 中添加了app:suffixText="PlaceHolder"。我希望默认显示suffixText ,但目前,仅当 TextInputLayout 获得焦点时它才可见。当 TextInputLayout 失去焦点时,我看不到 suffixText。这是我的代码-:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:suffixText="PlaceHolder"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:hint="hint">
<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)
请告诉我,如何默认显示后缀文本。
android android-layout material-design android-textinputlayout android-textinputedittext
我正在使用 AutoCompleteTextView 材料下拉列表将信息添加到我的 Firebase 数据库。这工作正常并且信息被正确捕获。
我现在希望允许我的用户编辑他们之前添加到数据库中的信息。我知道如何更新普通的 EditText 视图,但是当我对 AutoCompleteTextViews 使用相同的方法时,下拉列表仅显示存储在 Firebase 中的值,并且不显示选项的完整下拉列表,以便用户可以选择新值如果他们愿意的话。
我用来显示存储在这些下拉列表的数据库中的当前选定值的代码是
String activityType = data.getStringExtra("Activity_Type");
Run Code Online (Sandbox Code Playgroud)
然后我使用此代码填充下拉列表
editActivityTypeLayout = findViewById(R.id.editActivityTypeLayout);
editActivityType = findViewById(R.id.editActivityType);
final String[] type = new String[]{
"Formal Education Completed", "Other Completed", "Professional Activities", "Self-Directed Learning", "Work-Based Learning"
};
final ArrayAdapter<String> editAdapterType = new ArrayAdapter<>(
EditActivity.this,
R.layout.dropdown_item,
type
);
editActivityType.setAdapter(editAdapterType);
Run Code Online (Sandbox Code Playgroud)
但是,如果我包含第一行代码,则此代码不会填充下拉列表。
是否有不同的方式来显示下拉列表的当前值并显示其他选项?
java android android-textinputlayout material-ui material-components-android
我有一个固定高度的输入文本字段(TextInputLayout 的 EditText)。我想将提示文本与视图的左上角对齐。
问题:提示文本始终显示在 center_verticle,但我想将其显示在左上角。
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/aboutWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="About Sponsor">
<EditText
android:id="@+id/et_about_sponsor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="250dp"
android:textAlignment="viewStart"
android:layout_centerHorizontal="true"
android:gravity="start|top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textCapSentences"
android:textColor="@color/white"
android:textColorHint="@color/white"
android:textSize="@dimen/font_medium" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud) Android Studio 4.0.1
Robolectric 4.3.1
Run Code Online (Sandbox Code Playgroud)
我正在编写一个 robolectric 测试,测试将失败并出现以下错误。并且似乎与无法膨胀的TextInputLayout有关。如果我删除 TextInputLayout 测试将正常通过。
这是我收到的错误消息。
android.view.InflateException: Binary XML file line #47: Binary XML file line #47: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: android.view.InflateException: Binary XML file line #47: Error inflating class com.google.android.material.textfield.TextInputLayout
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
Run Code Online (Sandbox Code Playgroud)
测试类本身
@Config(sdk = [Build.VERSION_CODES.O_MR1])
@RunWith(AndroidJUnit4::class)
class CharitiesAdapterTest {
private lateinit var charitiesAdapter: CharitiesAdapter
@Before
fun setUp() {
charitiesAdapter = CharitiesAdapter()
}
@Test
fun `should …Run Code Online (Sandbox Code Playgroud) android robolectric android-textinputlayout instrumented-test
我在文本输入布局中有一个前缀文本,但仅当我单击文本输入编辑文本(位于具有前缀文本的文本输入布局内)时,它才会显示。如何使前缀文本始终显示提示
下面是我的文本输入编辑文本
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/til_number"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/til_country"
android:layout_marginStart="30dp"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="30dp"
android:layout_marginRight="30dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
app:boxBackgroundColor="#EFEFF2"
app:prefixText="+01 - "
app:shapeAppearanceOverlay="@style/RoundedTextInputLayout">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/et_first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="@string/number"
android:inputType="phone"
android:maxLength="100"
android:textSize="15sp" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我想实现的是
+01 - 
Run Code Online (Sandbox Code Playgroud)
前缀中的上述文本应始终显示
我尝试执行以下操作
app:prefixTextColor="@color/secondaryDarkColor"
Run Code Online (Sandbox Code Playgroud) prefix android-studio android-textinputlayout textinputlayout
我在这里读了android-developers的新博文.
TextInputLayout 扩展了浮动提示文本和错误指示符的现有功能,并增加了对字符计数的支持.
但我找不到任何编程方式的字符计数代码支持.我想一些代码来实现的字符计数使用TextInputLayout
我有一个TextInputLayout:
<android.support.design.widget.TextInputLayout
android:id="@+id/passwordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="#FFF"
android:theme="@style/TextInputLayoutWhite"
app:errorTextAppearance="@style/ErrorText"
app:hintTextAppearance="@style/TextInputLayoutWhite">
<EditText
android:id="@+id/passwordInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:imeOptions="actionGo"
android:singleLine="true"
android:textColor="#FFF"
app:theme="@style/WhiteEditText">
</EditText>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我在我的Activity中设置了一个错误,如下所示:
passwordLayout.setErrorEnabled(true);
这就是投掷 java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
如果我app:errorEnabled在我的xml布局中设置TextInputLayout,错误文本会显示,但我不希望它一直"启用",因为它为textview增加了额外的空间,直到我需要显示错误时才需要.
任何想法为什么这是扔java.lang.UnsupportedOperationException?这是完整的堆栈跟踪:
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x01010099
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x0101009a
03-16 19:31:22.078 32577-32577/com.example.myapp W/ResourceType: Too many attribute references, stopped at: 0x0101009b
03-16 19:31:22.078 32577-32577/com.example.myapp W/System.err: java.lang.UnsupportedOperationException: Can't convert to color: type=0x2
03-16 19:31:22.086 …Run Code Online (Sandbox Code Playgroud) 我的xml代码的密码字段部分:
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
...
<android.support.design.widget.TextInputLayout
android:layout_below="@+id/uname_ly"
android:id="@+id/text_input_layout_passwd"
app:layout_widthPercent="70%"
android:layout_centerHorizontal="true"
app:layout_heightPercent="10%"
app:layout_marginTopPercent="0%"
app:layout_marginBottomPercent="0%"
android:adjustViewBounds="true"
android:textColorHint="@color/editTextHintColor"
app:hintTextAppearance="@style/TextAppearance.App.TextInputLayout"
>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/nopasswd"
android:inputType="textPassword"
android:maxLines="1"
android:textColor="@color/editTextTextColor" />
</android.support.design.widget.TextInputLayout>
...
Run Code Online (Sandbox Code Playgroud)
[更新样式]
<style name="TextAppearance.App.TextInputLayout" parent="@android:style/TextAppearance">
<item name="android:textColor">@color/editTextHintColor</item>
</style>
Run Code Online (Sandbox Code Playgroud) android android-layout android-edittext android-styles android-textinputlayout
我最近将Android设计库从24.2.1升级到25.0.0.在此之后,EditText中的"drawableX"功能不起作用.
编辑01.11:我了解到如果你使用android:drawableStart而不是android:drawableLeft,在xml中设置drawable是有效的.但是以编程方式设置drawable不起作用.我使用它来制作一个"清除"按钮来清空EditText.但是这个功能现在已经破了.如果这是故意的谷歌或一个错误,我将不胜感激任何解决方法或知识!
我的可编辑文本的代码之前有效,但现在没有:
public class ClearableErrorTextInputEditText extends ErrorTextInputEditText implements View.OnFocusChangeListener, View.OnTouchListener, TextWatcher {
private Drawable resIcon;
private OnFocusChangeListener childFocusListener;
public ClearableErrorTextInputEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setup();
}
public ClearableErrorTextInputEditText(Context context, AttributeSet attrs) {
super(context, attrs);
setup();
}
public ClearableErrorTextInputEditText(Context context) {
super(context);
setup();
}
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (getCompoundDrawables()[2] != null) {
final boolean tappedClose = event.getX() > (getWidth() - getPaddingRight() - resIcon.getIntrinsicWidth());
if (tappedClose) …Run Code Online (Sandbox Code Playgroud) android android-edittext android-design-library android-textinputlayout
1. 什么android:hintAnimationEnabled用于TextInputLayout?
2. android:hintAnimationEnabled和之间的区别是android:hintEnabled什么?
android ×9
java ×2
hint ×1
material-components-android ×1
material-ui ×1
prefix ×1
robolectric ×1