Android工作室实现简易计算器

  

如果是制作简易计算器的话是基本没有难点的,供大家参考,具体内容如下

  

步骤是先写好界面布的局,将按钮的布局,字号颜色啥的做的好,再就是设置监听器。

  

使用了NoTitleBar的主题

  

代码如下:

  

activity_main里关于界面的代码:

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   LinearLayout & lt;   xmlns: android=" http://schemas.android.com/apk/res/android "   xmlns:应用=" http://schemas.android.com/apk/res-auto "   xmlns:工具=" http://schemas.android.com/tools "   android: layout_width=" match_parent "   android: layout_height=" match_parent "   android:取向=按怪薄?   工具:上下文=" .MainActivity "   比;      EditText & lt;   android: id=癅 + id/et_input”   android: layout_width="宽和"   android: layout_height=" 90 dp”   android:背景=" @drawable/white_bg”   android:可编辑=" false "   android:重力="右|下"   android: paddingBottom=" 20 dp”   android: paddingRight=" 20 dp”   android: textSize=" 50 sp”/比;      LinearLayout & lt;   android: layout_width="宽和"   android: layout_height=" wrap_content "   android: layout_marginTop=" 30 dp "   面向android:="水平"   android:重力=" center_horizontal "   比;   & lt;按钮   android: id=癅 + id/bt_clr”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" C "   android:重力="右|下"   android: textSize=" 30 sp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_del”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=皑尅?   android:重力="右|下"   android: textSize=" 30 sp”   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_div”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本="÷"   android: textSize=" 30 sp”   android:重力="右|下"   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_mul”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=啊痢?   android: textSize=" 30 sp”   android:重力="右|下"   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;/LinearLayout>      LinearLayout & lt;   android: layout_width="宽和"   android: layout_height=" wrap_content "   android: layout_marginTop=" 10 dp”   面向android:="水平"   android:重力=" center_horizontal "   比;   & lt;按钮   android: id=癅 + id/bt_7”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" 7 "   android:重力="右|下"   android: textSize=" 30 sp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_8”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" 8 "   android:重力="右|下"   android: textSize=" 30 sp”   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_9”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" 9 "   android: textSize=" 30 sp”   android:重力="右|下"   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_sub”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=?”   android: textSize=" 30 sp”   android:重力="右|下"   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;/LinearLayout>      LinearLayout & lt;   android: layout_width="宽和"   android: layout_height=" wrap_content "   android: layout_marginTop=" 10 dp”   面向android:="水平"   android:重力=" center_horizontal "   比;   & lt;按钮   android: id=癅 + id/bt_4”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" 4 "   android:重力="右|下"   android: textSize=" 30 sp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_5”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" 5 "   android:重力="右|下"   android: textSize=" 30 sp”   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_6”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" 6 "   android: textSize=" 30 sp”   android:重力="右|下"   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;按钮   android: id=癅 + id/bt_add”   android: layout_width=" 80 dp”   android: layout_height=" 80 dp”   android:文本=" + "   android: textSize=" 30 sp”   android:重力="右|下"   android: layout_marginLeft=" 10 dp”   android:背景=" @drawable/white_selector”   android: paddingRight=" 15 sp”   android: paddingBottom=" 15 sp”/比;   & lt;/LinearLayout>      LinearLayout & lt;   android: layout_width="宽和"   android: layout_height=" wrap_content "   面向android:="水平"   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

Android工作室实现简易计算器