我有一个带浮动提示的EditText,但我想知道如何减少浮动提示和EditText框之间的空间.
现在我的UI看起来像http://imgur.com/9hQzzx4,我想减少"标题"浮动提示和EditText框之间的空间.
这是我的xml文件的代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
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="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" >
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<EditText
style="@style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="40dp"
android:hint="Title"/>
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp">
<EditText
style="@style/Widget.AppCompat.EditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="32dp"
android:hint="Details"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout android-edittext android-textinputlayout
看起来TextInputLayout只是在里面不起作用ViewPager.
错误是:
扩展类android.support.design.widget.TextInputLayout时出错
Appcompat并Design library补充说.Theme是正确的.
我PageAdapter用来充气和填充ViewPager.
该TextInputLayout视图在应用程序的所有其他部分中都很好地膨胀.
在layout我膨胀了ViewPager.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.TextInputLayout
android:id="@+id/text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="My Edit Text" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我第一次使用新的Android的小部件TextInputLayout,它非常好但我使用setError方法遇到了一些问题
这是我的xml
<android.support.design.widget.TextInputLayout
android:id="@+id/userData_txtNameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textColorHint="@color/light_gray"
app:hintTextAppearance="@style/TextAppearence.App.TextInputLayout">
<EditText
android:id="@+id/userData_txtName"
style="@style/bold_textbox_style"
android:layout_width="match_parent"
android:layout_height="@dimen/textinut_height"
android:layout_margin="5dp"
android:hint="name"
android:imeOptions="actionNext"
android:inputType="text"
android:paddingTop="10dp"
android:textSize="@dimen/medium_text"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
怎么了:
我跑的时候
setError("error message")
Run Code Online (Sandbox Code Playgroud)
整个EditText背景和提示文本颜色变为红色,因为这里很好.问题是我跑的时候
setError(null)
Run Code Online (Sandbox Code Playgroud)
EditText的样式与原始样式完全不同.
开始情况:
后 setError("mandatory field")
后 setError(null)
我做了很多研究,但找不到任何有用的东西,问题到底是什么?
UPDATE
调查setError()方法的android源代码我发现了这个
public void setError(@Nullable CharSequence error) {
if (!mErrorEnabled) {
if (TextUtils.isEmpty(error)) {
// If error isn't enabled, and the error is empty, just return
return;
}
// Else, we'll assume that they want to enable the error functionality
setErrorEnabled(true); …Run Code Online (Sandbox Code Playgroud) 我想setError什么时候TextInputLayout isEmpty,我写这段代码但是当显示错误信息时,设置红色背景TextInputLayout!
我不想要设置背景!我只想显示错误消息.
我的代码:
if (TextUtils.isEmpty(userName)) {
register_UserName_layout.setError("Insert Username");
}
Run Code Online (Sandbox Code Playgroud)
XML代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/register_userUsernameTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register_headerLayout"
android:layout_margin="10dp"
android:textColorHint="#c5c5c5">
<EditText
android:id="@+id/register_userUserNameText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/selector_bg_edit"
android:hint="??? ??????"
android:paddingBottom="2dp"
android:textColor="@color/colorAccent"
android:textCursorDrawable="@drawable/bg_input_cursor"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?谢谢所有<3
我有我的AppTheme定义style.xml,我全局应用自定义样式为我所有的应用程序的TextView,EditText,Button等.
现在我想做同样的android.support.design.widget.TextInputEditText但是如何做?
它没有扩展,EditText因此忽略了样式.
这是我得到的:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary</item>
<item name="colorAccent">@color/accent</item>
<!-- Globally override default widget styles with custom -->
<item name="android:textViewStyle">@style/App.TextView</item>
<item name="android:editTextStyle">@style/App.EditText</item>
<item name="android:buttonStyle">@style/App.Button.Primary</item>
</style>
<style name="App.TextView" parent="@android:style/Widget.TextView">
<item name="android:textColor">@color/text</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textSize">@dimen/textsize_normal</item>
</style>
<style name="App.EditText" parent="@android:style/Widget.EditText">
<item name="android:textColor">#f00</item>
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textSize">@dimen/textsize_xxxlarge</item>
<item name="android:textStyle">bold</item>
<item name="android:textColorHint">@color/text_hint</item>
</style>
<style name="App.Button" parent="@android:style/Widget.Button">
<item name="android:textSize">@dimen/button_text_size</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textAllCaps">false</item> …Run Code Online (Sandbox Code Playgroud) android styles android-edittext material-design android-textinputlayout
我正在使用TextInputLayout来显示提示,但我无法将其垂直居中.我总是得到这个:
当EditText/TextInputEditText中没有文本时,我想垂直居中.我尝试过基本的想法(重力,layout_gravity等).到目前为止,唯一的方法是添加一些"魔术"填充,但我想以更清洁的方式做到这一点.我正在考虑测量顶部提示标签高度,并在它不可见时将其添加为底部边距,并在可见时删除相同的边距,但我还不太了解TextInputLayout源代码.有谁知道怎么做?
编辑:
我试过这个建议的答案:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:background="@color/grey_strong">
<android.support.design.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="90dp"
android:background="@color/red_light"
android:gravity="center_vertical"
android:hint="Test"/>
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我得到了这个:
"大"提示仍然没有垂直居中.它略低于中心,因为"小"提示(在灰色背景中,在顶部,仅在场聚焦时可见)在顶部占据一些空间并推动EditText.
android android-edittext android-textinputlayout android-gravity
我收到此错误:
无法解析符号'@ style/Widget.MaterialComponents.TextInputLayout.OutlineBox'
我在XML中将此行添加到TextInputLayout后出现此错误:
style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
Run Code Online (Sandbox Code Playgroud)
这是我的完整XML代码(删除了不相关的约束/边距):
<android.support.design.widget.TextInputLayout
android:id="@+id/textInputLayout2"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlineBox"
android:layout_width="match_parent"
android:layout_height="0dp"
app:counterEnabled="true"
app:counterMaxLength="300">
<android.support.design.widget.TextInputEditText
android:id="@+id/cheese_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:hint="@string/cheese_description" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的app build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 27
defaultConfig {
applicationId "app.cheese.cheese.some.sample_cheese"
minSdkVersion 19
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
buildToolsVersion '27.0.3'
}
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.google.firebase:firebase-auth:11.8.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.android.support:design:27.0.2'
compile …Run Code Online (Sandbox Code Playgroud) xml android android-appcompat android-design-library android-textinputlayout
在我的一个应用程序中,我将Theme.MaterialComponents.Light.NoActionBar用作基本样式。在我称之为 的这种样式中,AppTheme我试图覆盖editTextStyle以提供自定义样式com.google.android.material.textfield.TextInputEditText(根据源代码,它R.attr.editTextStyle用作默认样式)。
这是我当前的主题,与 TIEditText 和 TILayout 相关:
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
[ primary and secondary colors, OnColors, etc.]
<item name="editTextStyle">@style/AppTheme.TextInputEditText</item>
<item name="textInputStyle">@style/AppTheme.TextInputLayout</item>
[ Custom attribute for testing, defined in attrs.xml ]
<item name="textInputEditTextStyle">@style/AppTheme.TextInputEditText</item>
</style>
Run Code Online (Sandbox Code Playgroud)
出于某种原因,即使我设置了editTextStyle,如果我在代码中使用它,它也不会被应用:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/tilFirstName"
style="?attr/textInputStyle"
android:hint="@string/label_firstname"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstName"
style="?attr/editTextStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:text="@={viewModel.firstName}" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
但是,如果我替换firstNamewith的样式?attr/textInputEditTextStyle,它会起作用。
为什么我不能覆盖editTextStyle默认主题?这到底是怎么回事?
目标 SDK 为 28,minSDK 为 21,材质库版本为 1.1.0-alpha06
android android-edittext android-textinputlayout material-components material-components-android
我想创建textfield与hint文本jetpackcompose。任何示例如何创建textfield使用jectpack?谢谢
android android-textinputlayout android-jetpack-compose android-compose-textfield
嗨,我需要删除我的 TextField 中的下划线,因为当 TextField 是圆形时它看起来很难看。我已经将 activeColor 设置为透明,但是光标不会显示(因为它是透明的)。如何删除下划线/activeColor 并保留光标?
这是我的循环文本字段代码:
@Composable
fun SearchBar(value: String) {
// we are creating a variable for
// getting a value of our text field.
val inputvalue = remember { mutableStateOf(TextFieldValue()) }
TextField(
// below line is used to get
// value of text field,
value = inputvalue.value,
// below line is used to get value in text field
// on value change in text field.
onValueChange = { inputvalue.value = it },
// below line …Run Code Online (Sandbox Code Playgroud) android android-textinputlayout android-jetpack-compose android-compose-textfield android-jetpack-compose-text