如何解决材质TextInputEditText无法居中显示提示,也无法将输入值移到底部
在https://material.io/components/text-fields上有一个针对Filled TextField的交互式演示。 标签提示位于输入字段的中心,当您单击它并输入一些文本时,标签会向上移动,并且您输入的文本会稍微低于中心(低于之前的提示)
问题是我无法在Android上重现此行为,因为我输入的文本与占位符的位置相同。
提示和图标未居中,但应该
这是正确的,因为标签被向上移动并且密码在中心线以下
代码:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/et_password"
style="@style/Widget.MaterialComponents.TextInputLayout.FilledBox.Dense"
android:layout_width="0dp"
android:layout_height="65dp"
android:layout_marginTop="16dp"
android:background="@drawable/edittext_bg"
android:hint="@string/password"
app:BoxstrokeWidth="1dp"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/tiet_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:inputType="textPassword"
android:textSize="17sp" />
</com.google.android.material.textfield.TextInputLayout>
解决方法
尝试
from django.shortcuts import render,redirect,get_object_or_404,HttpResponseRedirect
...
from django.contrib import messages
...
# Auth functions
def signupuser(request):
if request.method == 'GET':
return render(request,'registration/signupuser.html',{'form':UserCreationForm()})
else:
if request.POST['password1'] == request.POST['password2']:
try:
user = User.objects.create_user(request.POST['username'],password=request.POST['password1'])
user.save()
login(request,user)
# This message does not show in the redirect
messages.success(request,'User successfully created.')
return redirect('currentbooks')
except IntegrityError:
return render(request,{'form':UserCreationForm()})
else:
# This message does show up under render
messages.error(request,'Passwords do not match.')
return render(request,{'form':UserCreationForm()})
def loginuser(request):
if request.method == 'GET':
return render(request,'registration/loginuser.html',{'form':AuthenticationForm()})
else:
user = authenticate(request,username=request.POST['username'],password=request.POST['password'])
if user is None:
messages.error(request,'Username and password do not match.')
# This message does show up under render
return render(request,{'form':AuthenticationForm()})
else:
login(request,user)
# This message does not show up under redirect
messages.success(request,'Logged in successfully.')
return redirect('currentbooks')
@login_required
def logoutuser(request):
if request.method == 'POST':
logout(request)
# This message does not show up. I tried HttpResponseRedirect as a last option.
messages.success(request,'Logged out successfully!')
return HttpResponseRedirect(reverse_lazy('loginuser'))
@styles ...
<com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:hint="First Name"
android:layout_height="wrap_content"
app:hintTextAppearance="@style/formTextAppearance">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/firstNameEditText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="2dp"
android:importantForAutofill="no"
android:background="@null"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ "
android:inputType="textCapSentences"
android:maxLength="150"
android:textSize="18sp" />
</com.google.android.material.textfield.TextInputLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。