517 Stimmen

Wie wird Text in Android fett dargestellt?

Wie kann man die text/schrift Einstellungen in einem Android TextView ?

Wie kann man zum Beispiel den Text fett ?

6voto

Rajesh Naddy Punkte 1104

In meinem Fall, Übergabe Wert durch string.xml arbeitete mit html Tag

<string name="your_string_tag"> <b> your_text </b></string>

6voto

Dan Tilakaratne Punkte 71

Angenommen, Sie sind ein Neueinsteiger in Android Studio, Sie können es einfach in der Entwurfsansicht erledigen XML durch die Verwendung von

android:textStyle="bold"          //to make text bold
android:textStyle="italic"        //to make text italic
android:textStyle="bold|italic"   //to make text bold & italic

5voto

Amaresh Jana Punkte 732

Sie können dies für Schriftarten verwenden

eine Klasse namens TypefaceTextView erstellen und die TextView erweitern

private static Map mTypefaces;

public TypefaceTextView(final Context context) {
    this(context, null);
}

public TypefaceTextView(final Context context, final AttributeSet attrs) {
    this(context, attrs, 0);
}

public TypefaceTextView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);
    if (mTypefaces == null) {
        mTypefaces = new HashMap<String, Typeface>();
    }

    if (this.isInEditMode()) {
        return;
    }

    final TypedArray array = context.obtainStyledAttributes(attrs, styleable.TypefaceTextView);
    if (array != null) {
        final String typefaceAssetPath = array.getString(
                R.styleable.TypefaceTextView_customTypeface);

        if (typefaceAssetPath != null) {
            Typeface typeface = null;

            if (mTypefaces.containsKey(typefaceAssetPath)) {
                typeface = mTypefaces.get(typefaceAssetPath);
            } else {
                AssetManager assets = context.getAssets();
                typeface = Typeface.createFromAsset(assets, typefaceAssetPath);
                mTypefaces.put(typefaceAssetPath, typeface);
            }

            setTypeface(typeface);
        }
        array.recycle();
    }
}

Fügen Sie die Schriftart in den im Asset-Ordner erstellten Ordner fonts ein.

<packagename.TypefaceTextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1.5"
        android:gravity="center"
        android:text="TRENDING TURFS"
        android:textColor="#000"
        android:textSize="20sp"
        app:customTypeface="fonts/pompiere.ttf" />**here pompiere.ttf is the font name**

Platzieren Sie die Zeilen im übergeordneten Layout in der xml

 xmlns:app="http://schemas.android.com/apk/res/com.mediasters.wheresmyturf"
xmlns:custom="http://schemas.android.com/apk/res-auto"

3voto

Sanket Patankar Punkte 21
editText.setTypeface(Typeface.createFromAsset(getAssets(), ttfFilePath));
etitText.setTypeface(et.getTypeface(), Typeface.BOLD);

setzt sowohl das Schriftbild als auch den Stil auf Bold.

2voto

Salman Nazir Punkte 2489

In Kotlin können wir in einer Zeile

 TEXT_VIEW_ID.typeface = Typeface.defaultFromStyle(Typeface.BOLD)

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X