Custom Fonts and Custom Textview on Android

The constructor of TextView calls setTypeface(Typeface tf, int style) with the style parameter retrieved from the XML attribute android:textStyle. So, if you want to intercept this call to force your own typeface you can override this method as follow: public void setTypeface(Typeface tf, int style) { Typeface normalTypeface = Typeface.createFromAsset(getContext().getAssets(), “font/your_normal_font.ttf”); Typeface boldTypeface = Typeface.createFromAsset(getContext().getAssets(), … Read more

How to use standard attribute android:text in my custom view?

use this: public YourView(Context context, AttributeSet attrs) { super(context, attrs); int[] set = { android.R.attr.background, // idx 0 android.R.attr.text // idx 1 }; TypedArray a = context.obtainStyledAttributes(attrs, set); Drawable d = a.getDrawable(0); CharSequence t = a.getText(1); Log.d(TAG, “attrs ” + d + ” ” + t); a.recycle(); } i hope you got an idea

Binding to custom control inside DataTemplate for ItemsControl

The problem is that you explicitly set the DataContext of your UserControl to itself: DataContext=”{Binding Mode=OneWay, RelativeSource={RelativeSource Self}} Remove that assignment and write the ItemName binding like this: <TextBlock Text=”{Binding ItemName, RelativeSource={RelativeSource AncestorType=UserControl}}”/> or like this <TextBlock Text=”{Binding ItemName, ElementName=ItemRowControl}”/>

How to create a User Control with rounded corners?

If you want really round corner and not only transparent trick you can use this example: private int radius = 20; [DefaultValue(20)] public int Radius { get { return radius; } set { radius = value; this.RecreateRegion(); } } [System.Runtime.InteropServices.DllImport(“gdi32.dll”)] private static extern IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int … Read more

How to draw a shape using GraphicsPath to create the Region of a Custom Control?

A few pointers and an example on the use of Regions to define the visible area of a Custom Control that represents a non rectangular shape. You’re converting most floating point values to integer values: don’t do that when drawing, unless you have no other immediate choice. Drawing requires floating point measures (float) most of … Read more