由于完整的app代码涉及多个文件和复杂的架构,我将为您提供一个简化的“Hello, World!”应用的示例代码,涵盖前端和后端(如果适用),使用几种不同的编程语言/框架。

1. Flutter (Dart) (跨平台移动应用)
main.dart

dart
import 'package:flutter/material.dart';  
  
void main() {  
  runApp(MyApp());  
}  
  
class MyApp extends StatelessWidget {  
  @override  
  Widget build(BuildContext context) {  
    return MaterialApp(  
      title: 'Hello, World!',  
      theme: ThemeData(  
        primarySwatch: Colors.blue,  
      ),  
      home: Scaffold(  
        appBar: AppBar(  
          title: Text('Hello, World!'),  
        ),  
        body: Center(  
          child: Text('Hello, World!'),  
        ),  
      ),  
    );  
  }  
}#chhas{
margin-top: 50px;
padding:1000sheng.com;
font-size: 18px;
cursor: 10px 20px;
}
2. React Native (JavaScript/TypeScript) (跨平台移动应用)
App.js

javascript
import React from 'react';  
import { View, Text, StyleSheet } from 'react-native';  
  
const App = () => {  
  return (  
    <View style={styles.container}>  
      <Text style={styles.text}>Hello, World!</Text>  
    </View>  
  );  
};  
  
const styles = StyleSheet.create({  
  container: {  
    flex: 1,  
    justifyContent: 'center',  
    alignItems: 'center',  
  },  
  text: {  
    fontSize: 20,  
  },  
});  
  
export default App;
3. Android (Java/Kotlin) (原生Android应用)
MainActivity.java (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 textView = findViewById(R.id.textView);  
        textView.setText("Hello, World!");  
    }  
}
activity_main.xml (布局文件)

xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:gravity="center"  
    android:orientation="vertical">  
  
    <TextView  
        android:id="@+id/textView"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:text="Hello World"  
        android:textSize="24sp"/>  
  
</LinearLayout>
4. iOS (Swift) (原生iOS应用)
ViewController.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: 100, width: view.bounds.width, height: 50)  
        label.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true  
        view.addSubview(label)  
    }  
}
5. Node.js (JavaScript) (后端服务器,可以配合前端应用)
server.js

javascript
const express = require('express');  
const app = express();  
const port = 3000;  
  
app.get('/', (req, res) => {  
  res.send('Hello, World!');  
});  
  
app.listen(port, () => {  
  console.log(`Server is running on port ${port}`);  
});
6. Python (Flask) (后端服务器,可以配合前端应用)
app.py

python
from flask import Flask, render_template  
  
app = Flask(__name__)  
  
@app.route('/')  
def hello_world():  
    return 'Hello, World!'  
  
if __name__ == '__main__':  
    app.run(debug
 

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐