Quiero tener un estilo de fuente diferente para la sugerencia y el estilo de fuente para el texto escrito en edittext. Por ej. Digamos que el tamaño de fuente de sugerencia es 12 y su tipo normal. Pero cuando el usuario comienza a escribir en el texto de edición, el tamaño de fuente del texto escrito debe ser 14 y negrita. nuevamente, si el usuario elimina el texto, la sugerencia debería ser del tipo mencionado anteriormente.Estilo de fuente de sugerencia diferente y escrito en estilo de fuente de texto android
6
A
Respuesta
4
Se puede cambiar mediante programación el color de pista para que sea diferente de estilo de fuente escrito en EditarTexto utilizando el siguiente código
editTextId.setHintTextColor(Color.alpha(006666));
0
La respuesta ya dada es correcta, pero actualmente especificar un color diferente es posible también en el Archivo XML a través del atributo android: textColorHint. Por ejemplo, podría hacer algo como esto (suponiendo que haya definido su my_favourite_colour correctamente como un recurso):
<EditText
... other properties here ...
android:textColorHint="@color/my_favourite_colour"
</EditText>
0
se puede lograr usando SpannableString
y MetricAffectingSpan
. Podrás cambiar la fuente, el tamaño y el estilo de la sugerencia.
1) Crear un objeto personalizado Hint
:
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.MetricAffectingSpan;
public class CustomHint extends SpannableString
{
public CustomHint(final CharSequence source, final int style)
{
this(null, source, style, null);
}
public CustomHint(final CharSequence source, final Float size)
{
this(null, source, size);
}
public CustomHint(final CharSequence source, final int style, final Float size)
{
this(null, source, style, size);
}
public CustomHint(final Typeface typeface, final CharSequence source, final int style)
{
this(typeface, source, style, null);
}
public CustomHint(final Typeface typeface, final CharSequence source, final Float size)
{
this(typeface, source, null, size);
}
public CustomHint(final Typeface typeface, final CharSequence source, final Integer style, final Float size)
{
super(source);
MetricAffectingSpan typefaceSpan = new CustomMetricAffectingSpan(typeface, style, size);
setSpan(typefaceSpan, 0, source.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
}
2) Crear la costumbre MetricAffectingSpan
objeto:
import android.graphics.Typeface;
import android.text.TextPaint;
import android.text.style.MetricAffectingSpan;
public class CustomMetricAffectingSpan extends MetricAffectingSpan
{
private final Typeface _typeface;
private final Float _newSize;
private final Integer _newStyle;
public CustomMetricAffectingSpan(Float size)
{
this(null, null, size);
}
public CustomMetricAffectingSpan(Float size, Integer style)
{
this(null, style, size);
}
public CustomMetricAffectingSpan(Typeface type, Integer style, Float size)
{
this._typeface = type;
this._newStyle = style;
this._newSize = size;
}
@Override
public void updateDrawState(TextPaint ds)
{
applyNewSize(ds);
}
@Override
public void updateMeasureState(TextPaint paint)
{
applyNewSize(paint);
}
private void applyNewSize(TextPaint paint)
{
if (this._newStyle != null)
paint.setTypeface(Typeface.create(this._typeface, this._newStyle));
else
paint.setTypeface(this._typeface);
if (this._newSize != null)
paint.setTextSize(this._newSize);
}
}
3) Uso:
Typeface newTypeface = Typeface.createFromAsset(getAssets(), "AguafinaScript-Regular.ttf");
CustomHint customHint = new CustomHint(newTypeface, "Enter some text", Typeface.BOLD_ITALIC, 60f);
// CustomHint customHint = new CustomHint(newTypeface, "Enter some text", Typeface.BOLD_ITALIC);
// CustomHint customHint = new CustomHint(newTypeface, "Enter some text", 60f);
// CustomHint customHint = new CustomHint("Enter some text", Typeface.BOLD_ITALIC, 60f);
// CustomHint customHint = new CustomHint("Enter some text", Typeface.BOLD_ITALIC);
// CustomHint customHint = new CustomHint("Enter some text", 60f);
customEditText.setHint(customHint);
Cuestiones relacionadas
- 1. Android: Estilo de preferencia
- 2. Pdf estilo de fuente nítido Negrita, cursiva y subrayado juntas
- 3. ggplot2: Estilo de fuente en la expresión de etiqueta
- 4. Etiqueta de estilo HTML equivalente a "tamaño de fuente + 2"
- 5. ¿Cómo establecer el estilo de fuente en negrita, cursiva y subrayado en una vista de texto de Android?
- 6. Estilo fuente para Google Code Jam
- 7. Color de fuente HTML/CSS frente al estilo de trama
- 8. ¿Cómo puedo cambiar el estilo de fuente en ActionBarSherlock
- 9. LINQ - ¿Estilo de sintaxis diferente, resultado diferente?
- 10. título preferencia Android estilo de texto/Resumen
- 11. Android - estilo de iPhone tabhost
- 12. Cómo hacer un texto en el estilo de fuente/peso negrita en JavaScript
- 13. Android - Combinación de varios estilos de fuente, en una sola fuente (tipo de letra)
- 14. Cómo cambiar solo el tamaño de fuente para todo el texto con estilo en NSTextView
- 15. Fuente personalizada en Android
- 16. Herencia de estilo basada en XAML diferente
- 17. Ancho y estilo de borde de cuadro de texto predeterminados
- 18. Cómo crear una fuente con + fontWithName: tamaño: y especifique el nombre de la familia de la fuente y la información de estilo específico para la fuente?
- 19. Obtener una ruta de archivo de fuente desde el nombre y el estilo en C++/Windows
- 20. Herencia de estilo en Android
- 21. WPF Cambiar fuente ¿El tamaño del botón con estilo falla?
- 22. Android aplicar el estilo de Vista de Texto de encargo
- 23. Barra de herramientas de estilo Color del texto - Android
- 24. Estilo de casilla de verificación de Android
- 25. Cómo comprobar si una fuente admite un estilo específico
- 26. Fuente de teclado Android
- 27. Eliminando el margen y cambiando el estilo de fuente para las etiquetas en ggplot
- 28. Cambiar el tamaño y el estilo de la fuente en Visual Studio 2008
- 29. Convertir código fuente ruby del viejo estilo al nuevo estilo hash
- 30. Cambiar el estilo de fuente - (Establecer texto de Lable en formato de mayúsculas) en el Objetivo C