MainActivity.kt
It seems like you're looking for a Kotlin file typically used in Android development, specifically for the MainActivity
. Below is a simple example of what a MainActivity.kt
file might look like in an Android application. This example includes basic setup for a simple app that displays a "Hello, World!" message.
package com.example.helloworld
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import android.widget.TextView
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Find the TextView in the layout and set its text
val textView: TextView = findViewById(R.id.textView)
textView.text = "Hello, World!"
}
}
AppCompatActivity
for compatibility with older Android versions and Bundle
for passing data.AppCompatActivity
, which is a base class for activities that use the support library action bar features.activity_main.xml
).TextView
in the layout and sets its text to "Hello, World!".You would also need a corresponding layout file (activity_main.xml
) in the res/layout
directory. Here’s a simple example of what that might look like:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
To run this app:
MainActivity.kt
with the provided code.activity_main.xml
in the res/layout
directory and add the provided XML code.Feel free to modify the code to suit your needs! If you have specific requirements or features you want to implement, let me know!