以下是双提示问题 - TextInputLayout and EditText double hint issue
我需要做同样的事情。我需要两个提示。一个是EditText的标题,第二个是可能的值,如果没有输入。
但不幸的是只有一个标签:
android:hint
我可以用它做点什么吗?
UPD1:
答案是以编程方式为EditText设置提示,并在xml中提示TextInputLayout。
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:hint="@string/prompt_quantity"
android:layout_height="wrap_content">
<EditText
android:id="@+id/quantity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:maxLines="1"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
和
quantityEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
quantityEditText.setHint(hasFocus ? "0" : "");
}
});
答案 0 :(得分:0)
只需检查您的输入并根据具体情况更改提示:
PSPath : Microsoft.PowerShell.Security\Certificate::CurrentUser\My\XXX
PSParentPath : Microsoft.PowerShell.Security\Certificate::CurrentUser\My
PSChildName : XXX
PSDrive : Cert
PSProvider : Microsoft.PowerShell.Security\Certificate
PSIsContainer : False
EnhancedKeyUsageList : {Code Signing (1.3.6.1.5.5.7.3.3)}
DnsNameList : {XXX}
SendAsTrustedIssuer : False
EnrollmentPolicyEndPoint : Microsoft.CertificateServices.Commands.EnrollmentEndPointProperty
EnrollmentServerEndPoint : Microsoft.CertificateServices.Commands.EnrollmentEndPointProperty
PolicyId :
Archived : False
Extensions : {System.Security.Cryptography.Oid, System.Security.Cryptography.Oid, System.Security.Cryptography.Oid,
System.Security.Cryptography.Oid...}
FriendlyName : XXX
IssuerName : System.Security.Cryptography.X509Certificates.X500DistinguishedName
NotAfter : XXX
NotBefore : XXX
HasPrivateKey : True
PrivateKey : System.Security.Cryptography.RSACryptoServiceProvider
PublicKey : System.Security.Cryptography.X509Certificates.PublicKey
RawData : XXX
SerialNumber : XXX
SubjectName : System.Security.Cryptography.X509Certificates.X500DistinguishedName
SignatureAlgorithm : System.Security.Cryptography.Oid
Thumbprint : XXX
Version : 3
Handle : XXX
Issuer : XXX
Subject : XXX
答案 1 :(得分:0)
试试这种方式
xml layout
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/non_active_edit_text"
android:focusable="false"
android:gravity="right|center_vertical"
android:hint="Right"
android:paddingTop="4dp"
android:background="@null"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/active_edit_text"
android:hint="Left"
android:layout_gravity="center_horizontal"/>
</merge>
JAVA课程
public class TwoHints extends RelativeLayout{
EditText activeField;
EditText nonActiveEditText;
final CharSequence hint;
public TwoHints(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(R.layout.two_hints_edit_text, this);
activeField = (EditText)findViewById(R.id.active_edit_text);
nonActiveEditText = (EditText)findViewById(R.id.non_active_edit_text);
hint = nonActiveEditText.getHint();
activeField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
nonActiveEditText.setHint(s.length() !=0 ? "" : hint);
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}
xml的editetext
<you.package.TwoHints
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
答案 2 :(得分:0)
您可以使用材料成分库
android:hint="Label"
添加浮动标签app:placeholderText="Placeholder Text"
在EditText
中添加一个占位符。使用类似的东西:
<com.google.android.material.textfield.TextInputLayout
android:hint="Label"
app:placeholderText="Placeholder Text"
..>
<com.google.android.material.textfield.TextInputEditText />
</com.google.android.material.textfield.TextInputLayout>
注意:它至少需要版本1.2.0-alpha03
。