Custom Fonts in Android

This is a simple example… create a folder in the root of your project called assets/fonts/ then paste the TTF font file (in this case Verdana.ttf). Then, if you want to apply that font to, say a TextView, do the following: import android.graphics.Typeface; public class FontSampler extends Activity { @Override public void onCreate(Bundle icicle) { … Read more

How to set both lines of a ListView using simple_list_item_2?

This questions ranks high with Google but I consider the given answer to be way too complicated. As pointed out in other answers, the desired functionality can be achieved using ArrayAdapter with a very easy trick. You can override the getView method of the ArrayAdapter: ArrayAdapter adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_2, android.R.id.text1, list) { @Override … Read more

how to set width which is equal to another widget on android

If you use a RelativeLayout you can use the align-attributes: <View android:id=”@+id/separator” android:layout_width=”0dp” android:layout_height=”0.3dp” android:layout_below=”@+id/textView1″ android:layout_alignLeft=”@+id/textView1″ android:layout_alignRight=”@+id/textView1″ android:background=”#ffffff” />

Changing size of seekbar thumb

The most flexible way to set thumb size for me is to create layered-drawable with shape as placeholder thumb_image.xml: <layer-list xmlns:android=”http://schemas.android.com/apk/res/android” > <item> <shape> <size android:height=”40dp” android:width=”40dp” /> <solid android:color=”@android:color/transparent” /> </shape> </item> <item android:drawable=”@drawable/scrubber_control_normal_holo”/> </layer-list> So basically changing the size of shape will stretch drawable, the shape is transparent so it won’t be visible. … Read more

how to validate a URL / website name in EditText in Android?

Short answer Use WEB_URL pattern in Patterns Class Patterns.WEB_URL.matcher(potentialUrl).matches() It will return True if URL is valid and false if URL is invalid. Long answer As of Android API level 8 there is a WEB_URL pattern. Quoting the source, it “match[es] most part of RFC 3987”. If you target a lower API level you could … Read more

Flutter: Is it somehow possible to create App Widgets (Android) and Today Extensions (iOS)? [duplicate]

There is no guide or docs showing how to implement a App Widget for a flutter app. It is definitely possible to implement a app widget with native code. Just create a flutter project and open the android part with android studio, just implement your home screen widget, it’ll work like a charm. I just … Read more