Skip to main content

Posts

Showing posts from April 14, 2017

Vertical AutoScrolling TextView in Android

In android by default we can scroll the text in horizontal using marquee in layout, but if we want to scroll the text in vertical its not possible by default. So here we will learn to create a custom TextView which will auto-scroll in vertical direction. Source Code:  VerticalScrollingTextView-Android Create a AutoScrollingTextView.class which extends TextView: @SuppressLint ( "AppCompatCustomView" ) public class AutoScrollingTextView extends TextView { private static final float DEFAULT_SPEED = 65.0f ; public Scroller scroller ; public float speed = DEFAULT_SPEED ; public boolean continuousScrolling = true; public AutoScrollingTextView (Context context) { super (context) ; init( null, 0 ) ; scrollerInstance(context) ; } public AutoScrollingTextView (Context context , AttributeSet attrs) { super (context , attrs) ; init(attrs , 0 ) ; scr

Custom FontTextView in Android

Customize font from layout for TextView In android layout textview  with font-family option with three fonts are given by default. If we have to add our own custom fonts from assert we have to do it by programmatically by adding these lines of code : TextView name = (TextView)findViewById(R.id.name);  Typeface type=Typeface.createFromAsset(getAssets(),"fonts/RobotoSlabRegular.ttf"); txtyour.setTypeface(type) ; Android 8.0 (API level 26) introduces a new feature, Fonts in XML, which lets you use fonts as resources. You can add the font file in the res/font/ folder to bundle fonts as resources. These fonts are compiled in your R file and are automatically available in Android Studio. You can access the font resources with the help of a new resource type, font . For example, to access a font resource, use @font/myfont , or R.font.myfont . To use the Fonts in XML feature on devices running Android 4.1 (API level 16) and higher, use the Support Library 26.