Android Question use custom font in xml

ArminKH

Well-Known Member
hi i'm using MSMaterialDrawer Lib which is created by @thedesolatesoul
as you can see on this thread https://www.b4x.com/android/forum/threads/msmaterialdrawer.53883/

we have a drawer which is not customizable and as you can see on this thread https://www.b4x.com/android/forum/threads/change-msmaterialdrawers-items-gravity.56318/#post-354775
i'm looking for a way to edit xml files to adjusting drawer for write to left language like PERSIAN
after some tests on xml file i'm succed to change the gravity for each item of drawer and now thats okay for persian language
but i'm sure you know the roboto font or sans serif which is default font for item's title is not suitable for all non-english languages,so i want to use my custom font for best results
here is my attrs.xml codes
B4X:
<?xml version="1.0" encoding="utf-8"?><resources>[/SIZE][/SIZE]
[SIZE=4][SIZE=3]
    <declare-styleable name="MaterialDrawer">
        <attr name="material_drawer_window_background" format="color|reference"/>
        <attr name="material_drawer_background" format="color|reference"/>

        <attr name="material_drawer_icons" format="color|reference"/>
        <attr name="material_drawer_primary_text" format="color|reference"/>
        <attr name="material_drawer_primary_icon" format="color|reference"/>
        <attr name="material_drawer_secondary_text" format="color|reference"/>
        <attr name="material_drawer_hint_text" format="color|reference"/>
        <attr name="material_drawer_divider" format="color|reference"/>

        <attr name="material_drawer_selected" format="color|reference"/>
        <attr name="material_drawer_selected_text" format="color|reference"/>
        <!-- material drawer header attrs-->
        <attr name="material_drawer_header_selection_text" format="color|reference"/>
    </declare-styleable>

    <declare-styleable name="ScrimInsetsView">
        <attr name="siv_insetForeground" format="reference|color"/>
    </declare-styleable>

    <declare-styleable name="BezelImageView">
        <attr name="biv_maskDrawable" format="reference"/>
        <attr name="biv_selectorOnPress" format="color|reference"/>
    </declare-styleable>

</resources>

and this is my xml code in material_drawer_item_primary.xml file which is a file of drawer in Layout folder in Res
B4X:
<?xml version="1.0" encoding="utf-8"?>[/SIZE][/SIZE]
[SIZE=4][SIZE=3]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

        android:layout_width="match_parent"
        android:layout_height="@dimen/material_drawer_item_primary"
        android:paddingLeft="@dimen/material_drawer_vertical_padding"
        android:paddingStart="@dimen/material_drawer_vertical_padding"
        android:paddingRight="@dimen/material_drawer_vertical_padding"
        android:paddingEnd="@dimen/material_drawer_vertical_padding">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="@dimen/material_drawer_item_primary"
        android:layout_height="@dimen/material_drawer_item_primary"
        android:paddingTop="@dimen/material_drawer_item_primary_icon_padding"
        android:paddingBottom="@dimen/material_drawer_item_primary_icon_padding"
        android:paddingLeft="@dimen/material_drawer_item_primary_icon_padding_right"
        android:paddingStart="@dimen/material_drawer_item_primary_icon_padding_right"
        android:layout_marginLeft="@dimen/material_drawer_item_padding"
        android:layout_marginStart="@dimen/material_drawer_item_padding"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="center_vertical"/>


    <LinearLayout
        android:layout_toLeftOf="@id/icon"
        android:layout_toStartOf="@id/icon"
        android:layout_toRightOf="@+id/badge"
        android:layout_toEndOf="@+id/badge"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:gravity="center_vertical|end"
        android:orientation="vertical">
      
        <TextView
            android:id="@+id/name"
            android:fontFamily="sans-serif"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/material_drawer_item_primary_text"
            android:gravity="center_vertical|right"
            android:lines="1"
            android:singleLine="true"
            tools:text="Some drawer text"/>
        <TextView
            android:id="@+id/description"
            android:fontFamily="sans-serif"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/material_drawer_item_primary_description"
            android:gravity="center_vertical|right"
            android:lines="1"
            android:singleLine="true"
            tools:text="Some drawer text"/>
    </LinearLayout>

    <TextView
        android:id="@+id/badge"
        android:fontFamily="sans-serif"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="@dimen/material_drawer_item_primary_text"
        android:gravity="center_vertical|start"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:lines="1"
        android:singleLine="true"
        tools:text="99"/>
</RelativeLayout>

so every body are familar with xml please help me
how is possible to set my custom font to each item of my drawer
thanx all
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
This kind of questions needs someone with better knowledge of xml-design (android design knowledge).
Most of the people here does not have this knowledge (me included)
 
Upvote 0

ArminKH

Well-Known Member
This kind of questions needs someone with better knowledge of xml-design (android design knowledge).
Most of the people here does not have this knowledge (me included)
thank u @DonManfred but then erel say dont limit your question to one member :D
 
Last edited:
Upvote 0

ArminKH

Well-Known Member
Last edited:
Upvote 0

mshafiee110

Active Member
Licensed User
Longtime User
hi i'm using MSMaterialDrawer Lib which is created by @thedesolatesoul
as you can see on this thread https://www.b4x.com/android/forum/threads/msmaterialdrawer.53883/

we have a drawer which is not customizable and as you can see on this thread https://www.b4x.com/android/forum/threads/change-msmaterialdrawers-items-gravity.56318/#post-354775
i'm looking for a way to edit xml files to adjusting drawer for write to left language like PERSIAN
after some tests on xml file i'm succed to change the gravity for each item of drawer and now thats okay for persian language
but i'm sure you know the roboto font or sans serif which is default font for item's title is not suitable for all non-english languages,so i want to use my custom font for best results
here is my attrs.xml codes
B4X:
<?xml version="1.0" encoding="utf-8"?><resources>[/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=4][SIZE=3][SIZE=4][SIZE=3]
    <declare-styleable name="MaterialDrawer">
        <attr name="material_drawer_window_background" format="color|reference"/>
        <attr name="material_drawer_background" format="color|reference"/>

        <attr name="material_drawer_icons" format="color|reference"/>
        <attr name="material_drawer_primary_text" format="color|reference"/>
        <attr name="material_drawer_primary_icon" format="color|reference"/>
        <attr name="material_drawer_secondary_text" format="color|reference"/>
        <attr name="material_drawer_hint_text" format="color|reference"/>
        <attr name="material_drawer_divider" format="color|reference"/>

        <attr name="material_drawer_selected" format="color|reference"/>
        <attr name="material_drawer_selected_text" format="color|reference"/>
        <!-- material drawer header attrs-->
        <attr name="material_drawer_header_selection_text" format="color|reference"/>
    </declare-styleable>

    <declare-styleable name="ScrimInsetsView">
        <attr name="siv_insetForeground" format="reference|color"/>
    </declare-styleable>

    <declare-styleable name="BezelImageView">
        <attr name="biv_maskDrawable" format="reference"/>
        <attr name="biv_selectorOnPress" format="color|reference"/>
    </declare-styleable>

</resources>

and this is my xml code in material_drawer_item_primary.xml file which is a file of drawer in Layout folder in Res
B4X:
<?xml version="1.0" encoding="utf-8"?>[/SIZE][/SIZE][/SIZE][/SIZE]
[SIZE=4][SIZE=3][SIZE=4][SIZE=3]
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"

        android:layout_width="match_parent"
        android:layout_height="@dimen/material_drawer_item_primary"
        android:paddingLeft="@dimen/material_drawer_vertical_padding"
        android:paddingStart="@dimen/material_drawer_vertical_padding"
        android:paddingRight="@dimen/material_drawer_vertical_padding"
        android:paddingEnd="@dimen/material_drawer_vertical_padding">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="@dimen/material_drawer_item_primary"
        android:layout_height="@dimen/material_drawer_item_primary"
        android:paddingTop="@dimen/material_drawer_item_primary_icon_padding"
        android:paddingBottom="@dimen/material_drawer_item_primary_icon_padding"
        android:paddingLeft="@dimen/material_drawer_item_primary_icon_padding_right"
        android:paddingStart="@dimen/material_drawer_item_primary_icon_padding_right"
        android:layout_marginLeft="@dimen/material_drawer_item_padding"
        android:layout_marginStart="@dimen/material_drawer_item_padding"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:layout_gravity="center_vertical"/>


    <LinearLayout
        android:layout_toLeftOf="@id/icon"
        android:layout_toStartOf="@id/icon"
        android:layout_toRightOf="@+id/badge"
        android:layout_toEndOf="@+id/badge"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:gravity="center_vertical|end"
        android:orientation="vertical">
     
        <TextView
            android:id="@+id/name"
            android:fontFamily="sans-serif"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/material_drawer_item_primary_text"
            android:gravity="center_vertical|right"
            android:lines="1"
            android:singleLine="true"
            tools:text="Some drawer text"/>
        <TextView
            android:id="@+id/description"
            android:fontFamily="sans-serif"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="@dimen/material_drawer_item_primary_description"
            android:gravity="center_vertical|right"
            android:lines="1"
            android:singleLine="true"
            tools:text="Some drawer text"/>
    </LinearLayout>

    <TextView
        android:id="@+id/badge"
        android:fontFamily="sans-serif"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:textSize="@dimen/material_drawer_item_primary_text"
        android:gravity="center_vertical|start"
        android:layout_alignParentStart="true"
        android:layout_alignParentLeft="true"
        android:lines="1"
        android:singleLine="true"
        tools:text="99"/>
</RelativeLayout>

so every body are familar with xml please help me
how is possible to set my custom font to each item of my drawer
thanx all
Hi @ArminKH
how are you?Is there something you found in this case؟
I am giiiiring it.
 
Upvote 0
Top