Set the TextView as the content view of the activity.īuild and run.Set “Hello Custom Views” as the text of the TextView.Create a TextView by using the constructor which needs the activity context.Open MainActivity and replace the setContentView(R.layout.activity_main) line in onCreate() with the following code: You can add a TextView to your layout from the Kotlin code. You have two ways to create a new instance of an Android view and to set values for its attributes: The following image shows a part of the basic widget hierarchy: It is (mostly) an empty project with some resources (colors, dimens and icon launcher).īuild and run the app, and you will see an empty screen like this:Īndroid has a set of basic widgets and the base class of any Android widget is the View class. To kick things off, start by downloading the materials for this tutorial (you can find a link at the top or bottom of the page) and then fire up Android Studio and import the starter project. To follow along with this tutorial, you’ll need to use Android Studio 3.0.1 or later and Kotlin 1.2.21 or later. If you’re completely new to Android, you might want to first check out Beginning Android Development Part One. Prerequisites: This Android tutorial is all about custom views, so you need basic knowledge of Android programming and familiarity with Kotlin, Android Studio, and XML layouts.
0 Comments
Leave a Reply. |