问题
I recently updated my support library to com.android.support:appcompat-v7:25.1.0
after which if I add a text to EditText
via xml file the TextInputLayout
hint doesn\'t float up.
I also had a look at this question but it didn\'t worked for me.
Here is my xml code:
<android.support.design.widget.TextInputLayout
android:layout_width=\"wrap_content\"
android:layout_height=\"wrap_content\"
android:layout_marginTop=\"16dp\"
app:layout_constraintTop_toTopOf=\"parent\"
app:layout_constraintBottom_toBottomOf=\"parent\"
android:layout_marginBottom=\"16dp\"
android:layout_marginEnd=\"16dp\"
app:layout_constraintRight_toRightOf=\"parent\"
android:layout_marginRight=\"16dp\"
app:layout_constraintVertical_bias=\"0.0\"
android:id=\"@+id/til1\"
android:layout_marginStart=\"16dp\"
app:layout_constraintLeft_toLeftOf=\"parent\"
android:layout_marginLeft=\"16dp\"
app:layout_constraintHorizontal_bias=\"0.33\">
<EditText
android:layout_width=\"match_parent\"
android:layout_height=\"wrap_content\"
android:hint=\"From\"
android:inputType=\"time\"
android:text=\"09:00 AM\"
android:id=\"@+id/from_mon\"
android:textSize=\"14sp\" />
</android.support.design.widget.TextInputLayout>
Here is my gradle dependencies:
dependencies {
compile fileTree(include: [\'*.jar\'], dir: \'libs\')
androidTestCompile(\'com.android.support.test.espresso:espresso-core:2.2.2\', {
exclude group: \'com.android.support\', module: \'support-annotations\'
})
compile \'com.android.support:appcompat-v7:25.1.0\'
compile \'com.android.support.constraint:constraint-layout:1.0.0-beta4\'
compile \'uk.co.chrisjenx:calligraphy:2.2.0\'
compile \'com.android.support:design:25.1.0\'
compile \'com.android.support:support-v4:25.1.0\'
compile \'com.android.support:recyclerview-v7:25.1.0\'
compile \'com.android.support:cardview-v7:25.1.0\'
compile \'com.android.volley:volley:1.0.0\'
compile \'com.github.bhargavms:DotLoader:1.0.1\'
compile \'com.github.bumptech.glide:glide:3.7.0\'
compile \'de.hdodenhof:circleimageview:2.1.0\'
compile \'com.labo.kaji:fragmentanimations:0.1.1\'
compile \'com.github.esafirm.android-image-picker:imagepicker:1.2.5\'
testCompile \'junit:junit:4.12\'
}
This is the problem
You can clearly see that the hint is floating up.
Please guide.
回答1:
You must provide hint to the TextInputLayout and use TextInputEditText instead of EditText
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="From">
<android.support.v7.widget.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="09:00 AM" />
</android.support.design.widget.TextInputLayout>
回答2:
After updating to version 25.1.0 of the v7 appcompat library, I faced many serious bugs in Toolbar
, RecyclerView
, etc.
I went back to version 25.0.1.
回答3:
UPDATE: The issue was fixed in 25.3.1
It is a bug in 25.1.0 https://code.google.com/p/android/issues/detail?id=230171 It seems we have to use previous 25.0.1 version for now.
回答4:
@Rahul Sharma,
Why you are using android:hint="From"
and android:text="09:00 AM"
in EditText tag of xml file?
Instead of that you can use only android:hint="From
in xml file and In Java code u can set text in dynamically.
I hope u will get my point. Thanks.
回答5:
This issue is fixed in Support Library Version 25.2.0. Please update to 25.2.0 This update includes other major fixes.
https://developer.android.com/topic/libraries/support-library/revisions.html#25-2-0
回答6:
Check your Do changes like this in you build.gradle for dependencies .. I think gradle is not a problem
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
}
If not solve by changes of gradle change First check basic changes in you inpul layout .. it will defiantly do your text float.. after do your changes.
<android.support.design.widget.TextInputLayout
android:id="@+id/til1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:layout_margin="10dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="From"
android:inputType="time"
android:text="09:00 AM"
android:id="@+id/from_mon"
android:textSize="14sp" />
</android.support.design.widget.TextInputLayout>
NOTE: And if possible set your hint in to string file .. may that will also be the issue.
来源:https://stackoverflow.com/questions/41135968/textinputlayout-hint-doesnt-float-up-after-updating-google-support-library