segmdl2.ttf
Agregamos la fuente y establecemos su Build Action como AndroidAsset.Typefaces.cs
Creamos la clase que nos permita construir la Typeface en base a la fuente que acabamos de agregar.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.App;
using Android.Graphics;
namespace Blog.Epicalsoft.Com.Droid
{
public class SegoeMDL2Typeface
{
public static Typeface Instance = Typeface.CreateFromAsset(Application.Context.Assets, "segmdl2.ttf");
private SegoeMDL2Typeface()
{
}
}
}
IconTextView.cs
Y ahora extendemos TextView para personalizarlo con el uso de la Typeface que acabamos de obtener.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Widget;
using System;
namespace Blog.Epicalsoft.Com.Droid.Views
{
public class IconTextView : TextView
{
public IconTextView(Context context) : base(context)
{
Typeface = SegoeMDL2Typeface.Instance;
Gravity = Android.Views.GravityFlags.CenterVertical;
}
public IconTextView(Context context, IAttributeSet attrs) : base(context, attrs)
{
Typeface = SegoeMDL2Typeface.Instance;
Gravity = Android.Views.GravityFlags.CenterVertical;
}
public IconTextView(Context context, IAttributeSet attrs, int defStyle) : base(context, attrs, defStyle)
{
Typeface = SegoeMDL2Typeface.Instance;
Gravity = Android.Views.GravityFlags.CenterVertical;
}
protected IconTextView(IntPtr javaReference, JniHandleOwnership transfer) : base(javaReference, transfer)
{
Typeface = SegoeMDL2Typeface.Instance;
Gravity = Android.Views.GravityFlags.CenterVertical;
}
}
}
Layout.axml
Una vez hecho esto ya esta todo listo para usar nuestro IconTextView.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<blog.epicalsoft.com.droid.views.IconTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="\uE001 " />
</LinearLayout>
No hay comentarios.:
Publicar un comentario