android studio简单的程序代码
时间: 2023-06-28 18:12:38 浏览: 48
以下是一个简单的 Android Studio 程序代码,用于创建一个带有 "Hello World!" 文本的空白屏幕:
在 `activity_main.xml` 中:
```xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/hello_world"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
```
在 `MainActivity.java` 中:
```java
package com.example.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView helloWorld = findViewById(R.id.hello_world);
helloWorld.setText("Hello World!");
}
}
```
这个简单的程序将在屏幕上显示文本 "Hello World!"。