Android studio开发-第一个应用

上效果图

1.先创建布局文件 firstbutton.xml

代码

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. tools:context=".MainActivity">
  8.  
  9. <TextView
  10. android:id="@+id/textView4"
  11. android:layout_width="113dp"
  12. android:layout_height="22dp"
  13. android:layout_marginBottom="336dp"
  14. android:text="这是第一个程序!"
  15. app:layout_constraintBottom_toBottomOf="parent"
  16. app:layout_constraintHorizontal_bias="0.472"
  17. app:layout_constraintLeft_toLeftOf="parent"
  18. app:layout_constraintRight_toRightOf="parent" />
  19.  
  20. <Button
  21. android:id="@+id/button"
  22. android:layout_width="89dp"
  23. android:layout_height="47dp"
  24. android:layout_marginStart="128dp"
  25. android:layout_marginLeft="128dp"
  26. android:layout_marginTop="50dp"
  27. android:layout_marginEnd="167dp"
  28. android:layout_marginRight="167dp"
  29. android:text="放大"
  30. android:onClick="bigger"
  31. app:layout_constraintEnd_toEndOf="parent"
  32. app:layout_constraintStart_toStartOf="parent"
  33. app:layout_constraintTop_toBottomOf="@+id/txv"
  34. tools:ignore="OnClick" />
  35.  
  36. <Button
  37. android:id="@+id/confirm"
  38. android:layout_width="wrap_content"
  39. android:layout_height="wrap_content"
  40. android:layout_marginStart="12dp"
  41. android:layout_marginLeft="12dp"
  42. android:layout_marginTop="377dp"
  43. android:layout_marginEnd="43dp"
  44. android:layout_marginRight="43dp"
  45. android:layout_marginBottom="86dp"
  46. android:text="修改"
  47. android:onClick="display"
  48. app:layout_constraintBottom_toBottomOf="parent"
  49. app:layout_constraintEnd_toEndOf="parent"
  50. app:layout_constraintStart_toEndOf="@+id/name"
  51. app:layout_constraintTop_toTopOf="parent" />
  52.  
  53. <EditText
  54. android:id="@+id/name"
  55. android:layout_width="166dp"
  56. android:layout_height="wrap_content"
  57. android:layout_marginStart="75dp"
  58. android:layout_marginLeft="75dp"
  59. android:layout_marginTop="54dp"
  60. android:layout_marginEnd="12dp"
  61. android:layout_marginRight="12dp"
  62. android:layout_marginBottom="88dp"
  63. android:ems=""
  64. android:inputType="textPersonName"
  65. android:hint="请输入要显示的字符"
  66. android:text="(名称输入栏)"
  67. app:layout_constraintBottom_toBottomOf="parent"
  68. app:layout_constraintEnd_toStartOf="@+id/confirm"
  69. app:layout_constraintStart_toStartOf="parent"
  70. app:layout_constraintTop_toBottomOf="@+id/button" />
  71.  
  72. <TextView
  73. android:id="@+id/txv"
  74. android:layout_width="wrap_content"
  75. android:layout_height="wrap_content"
  76. android:layout_marginStart="159dp"
  77. android:layout_marginLeft="159dp"
  78. android:layout_marginTop="36dp"
  79. android:layout_marginEnd="197dp"
  80. android:layout_marginRight="197dp"
  81. android:text="哈哈"
  82. app:layout_constraintEnd_toEndOf="parent"
  83. app:layout_constraintStart_toStartOf="parent"
  84. app:layout_constraintTop_toBottomOf="@+id/textView4" />
  85.  
  86. </android.support.constraint.ConstraintLayout>

修改java代码

插入代码

  1. package com.demo.my.myapplication;
  2.  
  3. import android.support.annotation.Nullable;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13. @Override
  14. protected void onCreate(@Nullable Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. setContentView(R.layout.firstbutton);
  17.  
  18. }
  19.  
  20. //添加布局
  21. int size=30; // 按钮对应的 onclick 响应
  22. public void bigger(View v){
  23. TextView txv;
  24. txv=(TextView) findViewById(R.id.txv); //根据ID找到对应的text对象
  25. txv.setTextSize(++size); //修改对象的字符大小-size
  26. }
  27.  
  28. //另一个按钮对应的onclick响应
  29. public void display(View v){
  30. EditText name=(EditText) findViewById(R.id.name); //根据ID找到对应的text对象,并进行接下来的操作
  31. TextView text2=(TextView) findViewById(R.id.txv);
  32. text2.setText(name.getText().toString()); //设置字符
  33.  
  34. }
  35.  
  36. }

Android studio开发-第一个应用的更多相关文章

  1. Android Studio开发第一篇QuickStart

    为什么把as的环境开发放在gradle里呢,因为eclipse里装gradle插件还是不够方便,as直接集成了,然后正好as也是大势所趋,学习一下正好. 看到右边Quick Start快速启动栏下面 ...

  2. 《Android Studio开发实战 从零基础到App上线》资源下载和内容勘误

    转载于:https://blog.csdn.net/aqi00/article/details/73065392 资源下载 下面是<Android Studio开发实战 从零基础到App上线&g ...

  3. windows平台下Android studio开发环境搭建教程

    最近,Google 已宣布,为了简化 Android 的开发力度,以重点建设 Android Studio 工具,到今年年底将停止支持Eclipse等其他集成开发环境 .而随着Android stud ...

  4. 使用 Android Studio 开发 widget 安卓桌面插件

    •What AppWidget 即桌面小部件,也叫桌面控件,就是能直接显示在Android系统桌面上的小程序: 这么说可能有点抽象,看图: 像这种,桌面上的天气.时钟.搜索框等等,都属于 APP Wi ...

  5. 使用Android Studio开发J2SE项目方法

    0.前言 最近因为要为项目开发一个底层的Java应用,所以非常偶然的遇到了这样一个问题,过去Eclipse有Java Project而现在手头使用Android Studio并不能直接建立Java应用 ...

  6. Android studio 开发环境搭建

    Android studio 开发环境搭建 一.环境: 下载java jdk:http://www.oracle.com/technetwork/cn/java/javase/downloads/jd ...

  7. 【Android 应用开发】Ubuntu 下 Android Studio 开发工具使用详解 (旧版本 | 仅作参考)

    . 基本上可以导入项目开始使用了 ... . 作者 : 万境绝尘 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/21035637 ...

  8. Android Studio开发环境配置以及相关说明

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 这里简单记录下在开发的时候使用的Android Studio开发环境版本以及相关注意事项. 一般来讲,每隔一段时间就要检查下Andr ...

  9. 【Android Studio安装部署系列】二、Android Studio开发环境搭建

    版权声明:本文为HaiyuKing原创文章,转载请注明出处! 概述 Android Studio开发环境安装步骤 下载Android Studio 下载地址: http://www.wanandroi ...

随机推荐

  1. ServiceStack学习之一准备工作

    GitHub:https://github.com/ServiceStack/ServiceStack/wiki 官网介绍的前期准备知识: Wikipedia article about HTTP a ...

  2. nohup 程序在后台运营 避免 xshell 卡死 通过 nohup.out分析调取系统命令时的异常分析

    nohup  程序在后台运营 避免 xshell  卡死 [root@admin1 after_fc_distributed]# nohup /root/anaconda3/bin/python da ...

  3. expand_dims

    tf.expand_dims  |  TensorFlow https://tensorflow.google.cn/api_docs/python/tf/expand_dims tf.expand_ ...

  4. 123 c#调用oracle存储过程返回数据集 --通过oracle存储过程返回数据集

    c#调用oracle存储过程返回数据集 2008-12-20 10:59:57|  分类: net|字号 订阅   CREATE OR REPLACE PACKAGE pkg_tableTypeIS  ...

  5. 学习Flash Builder编程的准备工作

    1. 下载教科书,Essential ActionScript 3.0或者Programming ActionScript 3.0.这将是你的很好的老师.英语不灵的买一本中文版本. 2. 安装Flas ...

  6. 【Codeforces】665E Beautiful Subarrays

    E. Beautiful Subarrays time limit per test: 3 seconds memory limit per test: 512 megabytes input: st ...

  7. SQL Server 方言类型映射问题

    关于SQL Server的类型映射问题,例如,nvarchar无法进行hibernate类型映射,需要通过convert进行类型转换方可进行获取

  8. bzoj3252攻略(线段树+dfs序)

    3252: 攻略 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 562  Solved: 238[Submit][Status][Discuss] D ...

  9. serlvet HttpServletRequest

    1.http://localhost/az/servlet/TestResponse out.print("getServletPath:"+request.getServletP ...

  10. hdu6198 number number number(递推公式黑科技)

    number number number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...