毕设第一部分

在value/res下建立string.xml想清楚自己的按钮名称,各种部件的名称和显示

<resources>

    <string name = "app_name">haha</string>
    <string name = "app_name2">you are clicked me!!!</string>
    <string name = "button1">red</string>
    <string name = "button2">blue</string>
    <string name ="button3">text</string>
</resources>

再设计好布局:布局有线性布局linearLayout,包括两种现形布局,垂直vertical,水平horizontal

相对布局RelativeLayout:是按照组件之间的相对位置来布局的,如在某个组件的上下左右

表格布局TableLayout

绝对布局:AbsoluteLayout

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
     <!-- 下面说明文本的id,长宽,还有显示的内容(要去string下面去找)-->
    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"

        android:text="@string/app_name" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/app_name2" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="2.79" >
         <!-- 下面说明按钮的id,大小,以及按钮上面的内容 -->
        <Button
            android:id="@+id/button1"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:text="@string/button1" />

        <Button
            android:id="@+id/button2"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:text="@string/button2" />

        <Button
            android:id="@+id/button3"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:text="@string/button3" />

    </LinearLayout>

</LinearLayout>

src下面的java文件

package org.test;

import com.example.test1.R;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Main_Activity extends Activity{//一定要继承Activity
     //创建属性
     private TextView text;
     private Button bt1;
     private Button bt2;
     private Button bt3;
     @Override
    //重写create方法
    public void onCreate(Bundle savedInstanceState)
    {
        //继承create方法
        super.onCreate(savedInstanceState);
        //调用setContentView方法显示布局文件
        setContentView(R.layout.main_layout1);
        //在OnCreate方法中通过调用findViewById()方法可以根据标识ID获取TextView控件
        text=(TextView)findViewById(R.id.textView1);
        // 在Oncreate方法中通过调用findViewById()方法可以根据标识ID获取Button控件
        bt1=(Button) findViewById(R.id.button1);
        bt2=(Button) findViewById(R.id.button2);
        bt3=(Button) findViewById(R.id.button3);
        text = (TextView) findViewById(R.id.textView2);
        //注册监听事件,ClickListener是事件监听器,该监听器实现OnClickListener接口
       bt1.setOnClickListener(new Button.OnClickListener(){
            @Override
            //重写OnClickListener接口中的onClick方法
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //通过getWindow()获取屏幕窗口,再调用setBackgroundDrawableResource()方法设置背景色
                //注意要在资源res/value文件夹下面建立color.xml来建立颜色
                getWindow().setBackgroundDrawableResource(R.color.red);

            }

        });
        bt2.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                getWindow().setBackgroundDrawableResource(R.color.blue);
            }

        });
        bt3.setOnClickListener(new Button.OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //监听按钮事件,点击按钮触发下面的行为
                text.setText("you are clicked me!!!!hahahahahahaha");
            }

        });
        String str="lalalalahahaha";
        //调用其setText方法设置显示的文字为字符串
        text.setText(str);
    }

}
  

color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="red">#FF0000</color>
    <color name="blue">#0000FF</color>
</resources>

再来看设置文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.test1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />
    <!--application:应用程序相关信息,这个元素中的两个属性分别制定应用程序的图标和标题  -->
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
       <!-- activity:活动信息,其中两个属性表明Activity的类名和标题 -->
        <activity android:name="org.test.Main_Activity" >
            <!--intent-filter:找到该Activity的过滤器,此处的Action子元素表明该Activity是程序的入口  -->
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <!-- 表明在加载程序时运行 -->
                <category android:name="android.intent.category.LAUNCHER"/>

            </intent-filter>
        </activity>
    </application>

</manifest>

android中的事件监听器:

OnclickListener单击事件

OnFocusChangeListener焦点事件

OnKeyListener按键事件

OnTouchListener触碰事件

OnCreateContextMenuListener创建上下文菜单事件

OnCheckedChangeListener选项事件

时间: 2024-08-29 02:29:48

毕设第一部分的相关文章

第一份代做毕设收入

Cache是位于CPU寄存器与内存之间的存储器,它的容量比内存小但交换速度快. Cache的工作原理 1.读取顺序 当数据从内存读入时,整行的数据(16~32字节)被装入Cache,如果程序具有良好的地址引用局部性(顺序浏览一个字符串),那么CPU以后对邻近数据的引用就可以从快速的Cache读取,而不用从缓慢的内存读取.典型情况下,主存的存取速度可能只有Cache的四分之一. CPU要读取一个数据时,首先从Cache中查找,如果找到就立即读取并送给CPU处理:如果没有找到,就用相对慢的速度从内存

php学习第一天-勤劳致富

所谓“勤劳致富”,是很有科学依据的,且是经过我的亲身实践的. 自毕设突然转变为开发项目之后,整个天都变了.先是妹子给我订的票被强行取消,然后又是师兄的一句“***一小时就搞定了”,说明一下这个***是我毕设劳动量的1/2,我只能底下默默感慨原来毕设水这么深,显然这个结论是在我一天学习后才得出的. 废话就屏蔽到这吧.由于我是web的小白,先学习了html语言,花了两小时.是在http://www.w3school.com.cn/index.html上学习的,对这个网站大赞.在自学了html后,师兄

第一天

从去年年底选毕设课题,我的专业是包装工程,选的题目是做一个网站,从选题的那一刻起,我就给自己选择了一份挑战,朋友开玩笑道:你这是给自己挖了一个坑,花样作死! 我大概从寒假开始写前端,真如朋友所说:在前端那块,我真的是花式被虐:不会写CSS,不会写jQuery,不会插入编辑器,不会让文本垂直居中,不会写图片轮播... ...反正就是各种不会,但是题目是自己选的,就算再难,也得坚持.好在有好多朋友.博客之类的,我不懂的就去找他们,基本上都能得到解决. 这大概就是背景.今天在去图书馆借书的路上,突然觉

毕设-家校通

一.主页 //Default1.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww

试用期第一个月感悟

2017年09月01日正式入职. 之前的比较正式的实习是在Robotron Datenbank-Software公司IT支持部写了一个工作流的申请物件系统,毕设做的是将该系统与公司的其他信息系统整合起来. 该系统的重点在于需要用到一个状态机.每个流程的点都加上一个status来维持该点的信息,包括读写权限.另外,主要是学习解决了AngularJS的前端异步请求时同步加载的问题. 该系统为本人第一次独立完成的一个小型系统.也为现在的入职工作做了一定的铺垫. 从入职到今天(09.30),正好满一个月

Swing:LookAndFeel 教程第一篇——手把手教你写出自己的 LookAndFeel

本文是 LookAndFeel 系列教程的第一篇. 是我在对 Swing 学习摸索中的一些微薄经验. 我相信,细致看全然系列之后.你就能写出自己的 LookAndFeel. 你会发现 Swing 原来能够这样美. -------------------------------------------------------------------------------- 引言: 我第一次接触 Java 要追溯到非常多年前做毕业设计的时候. 那天我和同学来到了一个微型软件公司(三程序猿.一会计.

java爬虫爬取学校毕设题目

背景 效果 思路 代码准备 依赖(jar包): 建表 代码 java爬虫过程解析 如何解决分页问题 背景 最近很多大四学生问我毕业设计如何选题 “你觉得图书管理系统怎么样?” “导师不让做这个,说太简单” “那你觉得二手交易平台怎么样?” “导师说没新意,都有咸鱼了你做这个有什么意思?要新颖的” “那你觉得个人博客平台的搭建怎么样?” “啥是博客?” “emmmm……在线售票怎么样?” “导师说今年不让选xx管理系统,这些都太简单” “那你觉得做人脸识别或者垃圾自动分类怎么样” “导师说这些太难

20165320 毕业设计 第一周总结

20165320 毕业设计 第一周总结 任务及完成情况 周一 周二 周三 周四 周五 周六 周天 Android运行及分析环境的搭建 学习Android系统 查阅Android系统安全相关文献 研究Android系统常见攻击与防护措施 根据现有资料制定学习计划 文献翻译.总结知识点 撰写总结博客 已完成 已完成 已完成 已完成 已完成 已完成 已完成 内容总结 一.环境搭建 JDK安装:Android的软件开发需要JDK支持,从官网或者通过其它途径获取安装包后,按照正常流程走完. 安装完成后添加

移除数组中第一个负数后的所有负数

scala> val a = ArrayBuffer[Int](1, 2,3, 5, -1, 2, -3, -5) a: scala.collection.mutable.ArrayBuffer[Int]= ArrayBuffer(1, 2, 3, 5, -1, 2, -3 , -5)   scala> :paste // Entering paste mode (ctrl-D tofinish)   var foundFirstNegative = false val keepIndexes