Android EditText ver Sugerencia Flotante en Material Design
La API 21 proporciona un método para usar la siguiente característica:
Http://www.google.com/design/spec/components/text-fields.html#text-fields-floating-labels
Estoy tratando de flotar las sugerencias de EditText.
Gracias!
9 answers
Sugerencia flotante EditText:
Agregue la siguiente dependencia en gradle:
compile 'com.android.support:design:22.2.0'
En el diseño:
<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/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="UserName"/>
</android.support.design.widget.TextInputLayout>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-07-01 07:35:12
Sí, a partir del 29 de mayo de 2015, esta funcionalidad ahora se proporciona en la Biblioteca de Soporte de Diseño de Android
Esta biblioteca incluye soporte para
- Etiquetas flotantes
- Botón de acción flotante
- Snackbar
- Cajón de navegación
- y más
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-02 08:54:28
La biblioteca de soporte de Android se puede importar dentro de gradle en las dependencias:
compile 'com.android.support:design:22.2.0'
Debe ser incluido dentro de GradlePlease! Y como ejemplo para usarlo:
<android.support.design.widget.TextInputLayout
android:id="@+id/to_text_input_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<AutoCompleteTextView
android:id="@+id/autoCompleteTextViewTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="To"
android:layout_marginTop="45dp"
/>
</android.support.design.widget.TextInputLayout>
Por cierto, el editor puede no entender que AutoCompleteTextView está permitido dentro de TextInputLayout.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-10 13:22:46
Android no ha proporcionado un método nativo. Ni el AppCompat.
Pruebe esta biblioteca: https://github.com/rengwuxian/MaterialEditText
Esto podría ser lo que quieres.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-08 14:37:58
Importa las Bibliotecas de Soporte, En la compilación de tu proyecto.gradle, agregue las siguientes líneas en las dependencias del proyecto:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:design:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
}
Use el siguiente TextInputLayout en su diseño de interfaz de usuario:
<android.support.design.widget.TextInputLayout
android:id="@+id/usernameWrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Username"/>
</android.support.design.widget.TextInputLayout>
Entonces, llama a setHint en TextInputLayout justo después de llamar a setContentView porque, para animar la etiqueta flotante, solo necesitas establecer una pista, usando el método setHint.
final TextInputLayout usernameWrapper = (TextInputLayout) findViewById(R.id.usernameWrapper);
usernameWrapper.setHint("Username");
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-09-01 06:58:53
La sugerencia de@andruboy de https://gist.github.com/chrisbanes/11247418 es probablemente su mejor apuesta.
Https://github.com/thebnich/FloatingHintEditText funciona con appcompat-v7 v21.0.0, pero como v21.0.0 no admite colores de acento con subclases de EditText
, el subrayado de FloatingHintEditText
será el blanco o negro sólido predeterminado. Además, el relleno no está optimizado para el estilo de material EditText
, por lo que es posible que deba ajustarlo.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-10-22 20:03:56
No, no lo hace. Esperaría esto en una futura versión de la api, pero por ahora estamos atascados con EditText. Otra opción es esta biblioteca:
https://github.com/marvinlabs/android-floatinglabel-widgets
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-06 18:26:51
Intenta de esta manera
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
}
Para más referencias haga clic en aquí
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-13 07:36:41
Para una manera más fácil de usar InputTextLayout, he creado esta biblioteca que corta su código XML a menos de la mitad, y también le proporciona la capacidad de establecer un mensaje de error, así como un mensaje de sugerencia y una manera fácil de hacer sus validaciones. https://github.com/TeleClinic/SmartEditText
Simplemente agregue
compile 'com.github.TeleClinic:SmartEditText:0.1.0'
Entonces puedes hacer algo como esto:
<com.teleclinic.kabdo.smartmaterialedittext.CustomViews.SmartEditText
android:id="@+id/emailSmartEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:setLabel="Email"
app:setMandatoryErrorMsg="Mandatory field"
app:setRegexErrorMsg="Wrong email format"
app:setRegexType="EMAIL_VALIDATION" />
<com.teleclinic.kabdo.smartmaterialedittext.CustomViews.SmartEditText
android:id="@+id/passwordSmartEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:setLabel="Password"
app:setMandatoryErrorMsg="Mandatory field"
app:setPasswordField="true"
app:setRegexErrorMsg="Weak password"
app:setRegexType="MEDIUM_PASSWORD_VALIDATION" />
<com.teleclinic.kabdo.smartmaterialedittext.CustomViews.SmartEditText
android:id="@+id/ageSmartEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:setLabel="Age"
app:setMandatory="false"
app:setRegexErrorMsg="Is that really your age :D?"
app:setRegexString=".*\\d.*" />
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-22 09:17:37