1、(一)、在MyDesktop主界面中添加应用图标1. 首先在我的桌面上添加你应用的图标以及文字,双击图标后就可以看见对应的代码,可直接在代码中进行修改图片文字的大小颜色等等。以下是对应图像图标的代码图片可以在左侧的选项中自行进行挑选;也可以添加自己的图片,只要将图片放到对应的文件夹之下在刷新就可以,但不建议放分辨率过高图片可能会出现超出界面的等错误。(二)、在res/layout目录下新建.xml文件,由于计算器的按钮很多,要在xml界面中添加排版:xml代码首末的 格式较为自由可以直接在界面中拖动图标位置以及修改大小,而其他layout则更会自动排列,各有优劣。(三)、在src/weibo.
2、test.ui目录下新建.java文件,计算器的按钮算法等都在此实现。(三)、声明工程名1、在应用中有三处需要声明,首先是在AndroidManifest.xml2、然后是在MainActivity.java四、 代码展示(一)、.xml界面代码LinearLayout xmlns:android= android:layout_width=fill_parentlayout_height=orientation=vertical /TableRow+id/tableRow1Button+id/bt_780pxtext=7 /+id/bt_88+id/bt_91px9+id/bt_backba
3、ck+id/tableRow2+id/bt_4+id/bt_55+id/bt_66+id/bt_divide/+id/tableRow3+id/bt_11+id/bt_22+id/bt_33+id/bt_multiply*+id/tableRow4+id/bt_050px0+id/bt_point.+id/bt_add+id/bt_sub-+id/bt_equal=+id/bt_clearclear/TableLayout/LinearLayout(二)、.java功能代码package weibo.test.ui;import java.util.ArrayList;import java.
4、util.List;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.Toast;import weibo.lixiaodaoaaa.ui.R;import android.content.Intent;import android.content
5、.pm.PackageManager;import android.view.KeyEvent;import android.widget.ListView;import com.zsy.flipper.AppInfUtil;import com.zsy.flipper.AppInfo;public class fffActivity extends Activity private Button bt_1; private Button bt_2; private Button bt_3; private Button bt_4; private Button bt_5; private B
6、utton bt_6; private Button bt_7; private Button bt_8; private Button bt_9; private Button bt_0; private Button bt_add; private Button bt_sub; / 减 private Button bt_multiply; / 乘 private Button bt_divide; / 除 private Button bt_back; private Button bt_equal; / 等于 private Button bt_point; / 点 private B
7、utton bt_clear; / 清除 private EditText et_play; / 显示 private String str_oper = ; / 运算符 private StringBuffer str_display = new StringBuffer(); private String str_result; / 结果显示 private double num1; private double num2; private boolean flag = true; / 小数点个数开关控制; private boolean b_sub, b_mul, b_div; / 运算
8、符开关控制 Override public void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState); setContentView(R.layout.activity_fff); bt_0 = (Button) findViewById(R.id.bt_0); bt_1 = (Button) findViewById(R.id.bt_1); bt_2 = (Button) findViewById(R.id.bt_2); bt_3 = (Button) findViewById(R.id.bt_3)
9、; bt_4 = (Button) findViewById(R.id.bt_4); bt_5 = (Button) findViewById(R.id.bt_5); bt_6 = (Button) findViewById(R.id.bt_6); bt_7 = (Button) findViewById(R.id.bt_7); bt_8 = (Button) findViewById(R.id.bt_8); bt_9 = (Button) findViewById(R.id.bt_9); bt_add = (Button) findViewById(R.id.bt_add); bt_sub
10、= (Button) findViewById(R.id.bt_sub); bt_multiply = (Button) findViewById(R.id.bt_multiply); bt_divide = (Button) findViewById(R.id.bt_divide); bt_back = (Button) findViewById(R.id.bt_back); bt_equal = (Button) findViewById(R.id.bt_equal); bt_point = (Button) findViewById(R.id.bt_point); bt_clear =
11、(Button) findViewById(R.id.bt_clear); et_play = (EditText) findViewById(R.id.et); et_play.setText(); bt_0.setOnClickListener(new OnClickListener() Override public void onClick(View v) str_display.append( et_play.setText(str_display.toString(); ); bt_1.setOnClickListener(new OnClickListener() bt_2.se
12、tOnClickListener(new OnClickListener() bt_3.setOnClickListener(new OnClickListener() bt_4.setOnClickListener(new OnClickListener() bt_5.setOnClickListener(new OnClickListener() bt_6.setOnClickListener(new OnClickListener() bt_7.setOnClickListener(new OnClickListener() bt_8.setOnClickListener(new OnC
13、lickListener() bt_9.setOnClickListener(new OnClickListener() bt_point.setOnClickListener(new OnClickListener() if (flag) str_display.append( flag = false; bt_back.setOnClickListener(new OnClickListener() if (str_display.length() != 0) str_display.deleteCharAt(str_display.length() - 1); et_play.setText(str_display.toString(); bt_add.setOnClickListener(new OnClickListener() str_oper = if (!(str_display.toString() = ) num1 += Double.parseDouble(str_display.toString(); str_display = new StringBuffer(str_result = null)
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1