Android (Java/Kotlin)joy-your-future.com
Java:
java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textView);
textView.setText("Hello, World!");
}
}
Kotlin:
kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView: TextView = findViewById(R.id.textView)
textView.text = "Hello, World!"
}
}
iOS (Swift)
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
label.center = self.view.center
self.view.addSubview(label)
}
}
Flutter (Dart)
dart
import ‘package:flutter/material.dart’;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: ‘Flutter Demo’,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text(‘Flutter Demo Home Page’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
React Native (JavaScript/TypeScript)
JavaScript:
javascript
import React from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;
const App = () => {
return (
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
},
});
export default App;
TypeScript:
(基本上与JavaScript相同,但你可以添加类型定义)
请注意,这些示例仅展示了如何在一个简单的屏幕上显示“Hello, World!”。要开发一个完整的App,你需要学习更多关于用户界面设计、状态管理、网络通信、数据存储等方面的知识。由于一个完整的App涉及多个层面(如用户界面、业务逻辑、数据存储等),且不同的平台和语言有不同的开发框架和工具,这里我将为你提供几种常见编程语言和框架的简短示例代码,这些代码将展示如何开始一个简单的App项目。
Android (Java/Kotlin)
Java:
java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textView = findViewById(R.id.textView);
textView.setText("Hello, World!");
}
}
Kotlin:
kotlin
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textView: TextView = findViewById(R.id.textView)
textView.text = "Hello, World!"
}
}
iOS (Swift)
swift
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let label = UILabel()
label.text = "Hello, World!"
label.frame = CGRect(x: 0, y: 0, width: 200, height: 50)
label.center = self.view.center
self.view.addSubview(label)
}
}
Flutter (Dart)
dart
import ‘package:flutter/material.dart’;
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: ‘Flutter Demo’,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: Text(‘Flutter Demo Home Page’),
),
body: Center(
child: Text(‘Hello, World!’),
),
),
);
}
}
React Native (JavaScript/TypeScript)
JavaScript:
javascript
import React from ‘react’;
import { View, Text, StyleSheet } from ‘react-native’;
const App = () => {
return (
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: ‘center’,
alignItems: ‘center’,
},
});
export default App;
TypeScript:
(基本上与JavaScript相同,但你可以添加类型定义)
请注意,这些示例仅展示了如何在一个简单的屏幕上显示“Hello, World!”。要开发一个完整的App,你需要学习更多关于用户界面设计、状态管理、网络通信、数据存储等方面的知识。