HarmonyOS_计算器样式UI

在这里插入图片描述

@Entry
@Component
struct Index {
   
   
  @Styles common(){
   
   
    .backgroundColor("#ccc")
    .borderRadius(6)
  }

  @State arrs: Array<string> = [
    "CE", "C", "/", "x",
    "7", "8", "9", "-",
    "4", "5", "6", "+",
    "1"
HarmonyOS中,你可以创建一个简单的计算器应用作为示例。这里是一个基本的步骤和部分代码片段,展示如何使用HMS(华为移动服务)框架实现: 首先,确保添加了必要的依赖,例如`com.huawei.hms.common`、`com.huawei.hms.app.launcher`等。然后,在MainActivity中进行初始化并启动CalculatorActivity: ```java import com.huawei.hms.app.launcher.HMSAppCompatActivity; import com.example.myapp.CalculatorActivity; public class MainActivity extends HMSAppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 检查是否安装了计算器应用 if (!HMSAppLauncher.isInstalled(this)) { // 如果未安装,跳转到应用商店安装 Intent installIntent = new Intent(); installIntent.setAction(Intent.ACTION_VIEW); installIntent.setData(Uri.parse("market://details?id=com.example.calculator")); startActivity(installIntent); finish(); // 立即退出 return; } // 启动计算器活动 Intent intent = new Intent(this, CalculatorActivity.class); startActivityForResult(intent, REQUEST_CODE_CALCULATOR); } // ... 其他方法和生命周期回调 @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_CODE_CALCULATOR && resultCode == RESULT_OK) { // 处理返回的结果 String result = data.getStringExtra(CalculatorActivity.RESULT_KEY); Toast.makeText(this, "计算结果:" + result, Toast.LENGTH_SHORT).show(); } } } // 计算器活动类 CalculatorActivity.java public class CalculatorActivity extends Activity { public static
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大众筹码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值