Customize text layout android

1

How can I customize the TextView? My idea is that some parts of the layout look more than others to make more emphasis in certain parts of the layout. Basically my idea is the one that appears in the image that I attached, but implemented in my app.

'

<LinearLayout
    android:id="@+id/saldoLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <TextView
        android:id="@+id/saldoTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="@string/saldo"
        android:textAlignment="center"
        android:textColor="@color/letra"
        android:textSize="24sp" />

</LinearLayout>

<LinearLayout
    android:id="@+id/activityStockLinearLayout"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/saldoLinearLayout"
    android:layout_weight="1"
    android:orientation="horizontal">

    <LinearLayout
        android:id="@+id/activityStockLinearLayoutLeft"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <TextView
            android:id="@+id/activityStockValue_textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="10.763,30" />

        <TextView
            android:id="@+id/activityStockName_textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="TextView"
            tools:text="IBEX 35" />

        <TextView
            android:id="@+id/activityStockIniciales_textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="^IBEX" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/activityStockLinearLayoutRight"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/activityStockLogoLinearLayoutRight"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        </LinearLayout>

        <LinearLayout
            android:id="@+id/activityStockValuesLinearLayoutRight"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"></LinearLayout>
    </LinearLayout>

</LinearLayout>

<LinearLayout
    android:id="@+id/graphLinearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/activityStockLinearLayout"
    android:orientation="horizontal">

</LinearLayout>

'

    
asked by Eduardo 02.05.2017 в 11:24
source

3 answers

0

I recommend that you use the predefined material styles of Android to avoid problems. But you can also define your own, for this you can modify the following parameters:

android:textStyle="normal|bold|italic"

With this you can have the letter in bold or italics. You can also change the source to a predefined one with:

android:fontFamily:"sans-serif"

and all its variants. You can also download a source on the internet and include it in your code:

texto = (TextView) rootview.findViewById(R.id.tvDefault);
    //Definicion de nuestro propio estilo de fuente
    String font_path = "font/AlexBrush-Regular.ttf";
    Typeface tf = Typeface.createFromAsset(rootview.getContext().getAssets(),font_path);
    texto.setTypeface(tf);

Finally, you only have to play with the color.

android:textColor = "@color/colorPrimary"

Which you can modify in the xml file located in values / colors.xml

    
answered by 02.05.2017 / 12:58
source
1

You can use the attributes in a TextView :

<item name="android:textColor">#ffffff</item>
<item name="android:textSize">30sp</item>
<item name="android:textStyle">bold</item>

The size specification is recommended to use unit sp which is scalable if the user in system preference defines the font size.

Letter Style Material Design

You can set a style that includes, size, typography and grossor, using android:textAppearance the following link there are references Type Design Material

Your use

<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="location"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Title" />

The ones you can use:

  • Base.TextAppearance.AppCompat.Display4
  • Base.TextAppearance.AppCompat.Display3
  • Base.TextAppearance.AppCompat.Display2
  • Base.TextAppearance.AppCompat.Display1
  • Base.TextAppearance.AppCompat.Headline
  • Base.TextAppearance.AppCompat.Title
  • Base.TextAppearance.AppCompat.Title.Inverse
  • Base.TextAppearance.AppCompat.Subhead
  • Base.TextAppearance.AppCompat.Subhead.Inverse
  • Base.TextAppearance.AppCompat.Body2
  • Base.TextAppearance.AppCompat.Body1
  • Base.TextAppearance.AppCompat.Caption
  • Base.TextAppearance.AppCompat.Menu
  • Base.TextAppearance.AppCompat.Button
answered by 02.05.2017 в 11:59
0

I come to teach you another super easy way, that will blow your head Using this dependency you will be able to customiser each text of everything you want in the easiest way possible, you only look for the sources that you will use on the internet and that's it, you declare them as they teach you in the dependency.

I always use it and I have something like this for example for a text:

<com.thebrownarrow.customfont.CustomFontTextView
                        android:id="@+id/tvRestaurantName"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:textColor="@color/cardview_light_background"
                        android:textSize="14sp"
                        android:text="Restaurant"
                        app:custom_typeface="fonts/estandar.ttf"/>
    
answered by 02.05.2017 в 14:53