无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)
1.Android是什么
手机设备的软件栈,包括一个完整的操作系统、中间件、关键的应用程序,底层是linux内核,安全管理、内存管理、进程管理、电源管理、硬件驱动 2.Dalvik VM 和 JVM 的比较
3.常见adb指令
platform-tools/adb.exe
adb.exe : android debug bridge android调试桥
adb devices:列出所以连接的设备
adb kill-server :杀死adb调试桥
adb start-server :启动adb调试桥
adb install xxx.apk 如果有多个设备,我们可以指定设备 adb install –s emulator-5554 D:/xxx.apk
adb uninstall 包名 : 卸载应用
adb pull 源文件 目标文件 : 导出文件
adb push 源文件 目标文件 : 导入文件 4.Android应用程序架构
5.程序打包&安装的过程
6.电话拨号器
代码提示键:Alt+/
出现黄色的解决方式:Ctrl+1
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PhoneActivity" > <EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
/>
<Button
android:id="@+id/bt_dail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/et_number"
android:text="@string/dail" /> </RelativeLayout> package com.example.demo1; import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; public class PhoneActivity extends Activity implements OnClickListener { private EditText dt_number = null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_phone);
Button bt_dail = (Button)this.findViewById(R.id.bt_dail);
dt_number = (EditText)this.findViewById(R.id.et_number);
bt_dail.setOnClickListener(this); } public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_dail:
String number = dt_number.getText().toString().trim();
if (TextUtils.isEmpty(number)) {
Toast.makeText(PhoneActivity.this, "号码不能为空!",
Toast.LENGTH_SHORT).show();
return;
}
Intent intent = new Intent();
intent.setAction(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + number));
startActivity(intent);
break;
default:
break;
} }
} <activity
android:name="com.example.demo1.PhoneActivity"
android:label="@string/title_activity_phone" >
<!--决定启动哪个activity-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<uses-permission android:name="android.permission.CALL_PHONE" /> 7.点击事件的4种写法
(1).创建一个内部类定义点击事件
bt_dail.setOnClickListener(new MyListener());
private class MyListener implements OnClickListener
(2).采用匿名内部类创建点击事件
bt_dail.setOnClickListener(new OnClickListener() { @Override
public void onClick(View v) {
// TODO Auto-generated method stub }
});
(3).让类实现点击事件的接口,(常用)
public class PhoneActivity extends Activity implements OnClickListener
public void onClick(View v) {
switch (v.getId()) {
case R.id.bt_dail:
default:
break;
}
(4).在布局文件中绑定一个点击(android:onClick="")
android:onClick="dail"
public void dail(View view) {} 8.短信发送器
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <EditText
android:id="@+id/et_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入电话号码" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/et_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入内容"
android:lines="5" />
<Button
android:id="@+id/bt_send"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="发送" />
</LinearLayout> package com.example.demo1; import java.util.ArrayList; import android.app.Activity;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast; public class SMSActivity extends Activity { private EditText mEditTextNumber = null;
private EditText mEditTextContent = null; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sms);
Button mButtonSend = (Button) this.findViewById(R.id.bt_send);
this.mEditTextNumber = (EditText) this.findViewById(R.id.et_number);
this.mEditTextContent = (EditText) this.findViewById(R.id.et_content);
mButtonSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String number = mEditTextNumber.getText().toString().trim();
String content = mEditTextContent.getText().toString().trim();
if (TextUtils.isEmpty(number) || TextUtils.isEmpty(content)) {
Toast.makeText(SMSActivity.this, "电话号码或内容不能为空!", 0).show();
} else {
PendingIntent sentIntent = PendingIntent.getBroadcast(SMSActivity.this, 0, new Intent(), 0);
SmsManager smsManager = SmsManager.getDefault(); //如果字数超过70,需拆分成多条短信发送
ArrayList<String> contents = smsManager.divideMessage(content);
for (String str : contents) {
//最后二个参数为短信已发送的广播意图,最后一个参数为短信对方已收到短信的广播意图
smsManager.sendTextMessage(number, null, str, sentIntent,null);
}
Toast.makeText(SMSActivity.this, "短信发送完成", Toast.LENGTH_LONG).show(); }
}
});
} } <uses-permission android:name="android.permission.SEND_SMS"/> 9. Android 中各种布局
<!-- LinearLayout - 线形布局。
orientation - 容器内元素的排列方式。vertical: 子元素们垂直排列;horizontal: 子元素们水平排列
gravity - 内容的排列形式。常用的有 top, bottom, left, right, center 等,详见文档 -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="right"
android:orientation="vertical" > <!-- FrameLayout - 层叠式布局。以左上角为起点,将 FrameLayout 内的元素一层覆盖一层地显示 --> <FrameLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FrameLayout" >
</TextView> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Frame Layout" >
</TextView>
</FrameLayout>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@string/hello_world" />
<!--
TableLayout - 表格式布局。
TableRow - 表格内的行,行内每一个元素算作一列
collapseColumns - 设置 TableLayout 内的 TableRow 中需要隐藏的列的列索引,多个用“,”隔开
stretchColumns - 设置 TableLayout 内的 TableRow 中需要拉伸(该列会拉伸到所有可用空间)的列的列索引,多个用“,”隔开
shrinkColumns - 设置 TableLayout 内的 TableRow 中需要收缩(为了使其他列不会被挤到屏幕外,此列会自动收缩)的列的列索引,多个用“,”隔开
-->
<TableLayout android:id="@+id/TableLayout01"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:collapseColumns="1">
<TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_weight="1" android:layout_height="wrap_content"
android:text="行1列1" />
<TextView android:layout_width="wrap_content"
android:layout_weight="1" android:layout_height="wrap_content"
android:text="行1列2" />
<TextView android:layout_width="wrap_content"
android:layout_weight="1" android:layout_height="wrap_content"
android:text="行1列3" />
</TableRow>
<TableRow android:id="@+id/TableRow01" android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="行2列1" />
</TableRow>
</TableLayout>
<!--
AbsoluteLayout - 绝对定位布局。
layout_x - x 坐标。以左上角为顶点
layout_y - y 坐标。以左上角为顶点
-->
<AbsoluteLayout android:layout_height="wrap_content"
android:layout_width="fill_parent">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="AbsoluteLayout"
android:layout_x="100px"
android:layout_y="100px" />
</AbsoluteLayout> <!--
RelativeLayout - 相对定位布局。
layout_centerInParent - 将当前元素放置到其容器内的水平方向和垂直方向的中央位置(类似的属性有 :layout_centerHorizontal, layout_alignParentLeft 等)
layout_marginLeft - 设置当前元素相对于其容器的左侧边缘的距离
layout_below - 放置当前元素到指定的元素的下面
layout_alignRight - 当前元素与指定的元素右对齐
-->
<RelativeLayout android:id="@+id/RelativeLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<TextView android:layout_width="wrap_content" android:id="@+id/abc"
android:layout_height="wrap_content" android:text="centerInParent=true"
android:layout_centerInParent="true" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="marginLeft=20dp"
android:layout_marginLeft="20dp" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="xxx"
android:layout_below="@id/abc" android:layout_alignRight="@id/abc" />
</RelativeLayout>
</LinearLayout>
无废话Android之常见adb指令、电话拨号器、点击事件的4种写法、短信发送器、Android 中各种布局(1)的更多相关文章
- Android journey3 @点击事件的4种写法
对于android布局中的控件,如Button等会有相应的点击事件去响应它所需要的功能,今天我们就以电话拨号器的代码说明下几种点击事件: package com.itheima.phone; impo ...
- Android笔记---点击事件的四种写法
Android 点击事件的四种写法: 1. 以内部类的形式实现 OnClickListener 接口.定义点击事件 class MainActivity extents Activity{ // .. ...
- Android中点击事件的四种写法详解
Android中点击事件的四种写法 使用内部类实现点击事件 使用匿名内部类实现点击事件 让MainActivity实现View.OnClickListener接口 通过布局文件中控件的属性 第一种方法 ...
- [Android] 点击事件的四种写法
点击事件的必备条件:实现OnClickListener接口,重写onclick(View v)方法 以拨号简单案例为例,如下图效果: 逻辑流程: 获取点击对象,获取数据 给对象设置监听类 实现OnCl ...
- [Android]Java中点击事件的四种写法
点击事件的必备条件:实现OnClickListener接口,重写onclick(View v)方法 以拨号简单案例为例,如下图效果: 逻辑流程: 获取点击对象,获取数据 给对象设置监听类 实现OnCl ...
- 【转】Android - Button(按钮)的响应点击事件的4种写法
原文网址:http://www.yrom.net/blog/2011/12/12/android-4-onclicklistener-of-button/ Button控件setOnclickList ...
- android中点击事件的4种写法
android中获取到一些控件(比如说按钮)时,一般会为其添加点击事件,android中的点击事件一共有4中写法. 假设在布局文件中声明如下 ....... <Button android:la ...
- Android - Button(按钮)的响应点击事件的4种写法
Button控件setOnclickListener(View.OnClickListener listener)来接收一个点击事件的监听器 自定义一个点击事件监听器类让其实现View.OnClick ...
- Android代码学习--点击事件的几种写法
由来:常规的写法参见<写一个apk>,每次点击按钮,按钮先查找文本框等元素,然后再操作,其实查找操作是很费时的操作,因此将该定义放到Activity的onCreate中:Oncreate只 ...
随机推荐
- centos 本地dns配置
折腾了差不多两天,看了不少中文,英文文档.终于搞定,记录下心得.本文只讨论正向解析. 安装 ============= yum install bind 全局配置 ========= 由于只是做本地d ...
- C#调用有有参有返的存储过程
(1)在SQL Server中建立如下的存储过程: set ANSI_NULLS ONset QUOTED_IDENTIFIER ONGOCREATE PROCEDURE [dbo].[GetName ...
- 1个简单的Log
#pragma once #include <windows.h> #include <process.h> class CLogger { public: static CR ...
- history/location操作 /navigator 操作/ screen操作
话说mac真的没广告...就凭这点,mac完胜.ei capitan 好牛畅,分屏很好用啊,回不去了. var hist=window.history; hist.go(param); // para ...
- poj 1326
http://poj.org/problem?id=1326 一个模拟的水题 题意就是要你算飞行的英里数. F代表头等舱,为实际飞行的英里数的2倍. B为商务舱,为实际飞行的英里数的1.5倍. Y为经 ...
- Divide and conquer:Subset(POJ 3977)
子序列 题目大意:给定一串数字序列,要你从中挑一定个数的数字使这些数字和绝对值最小,求出最小组合数 题目的数字最多35个,一看就是要数字枚举了,但是如果直接枚举,复杂度就是O(2^35)了,显然行不通 ...
- 【STL】 set集合容器常用用法
set集合容器:实现了红黑树的平衡二叉检索树的数据结构,插入元素时,它会自动调整二叉树的排列,把元素放到适当的位置,以保证每个子树根节点键值大于左子树所有节点的键值,小于右子树所有节点的键值:另外,还 ...
- log4j:WARN No appenders could be found for logger
直接写我的解决办法: 在src下面新建file名为log4j.properties内容如下:# Configure logging for testing: optionally with log f ...
- C#中XmlTextWriter读写xml文件详细介绍(转)
转自http://www.jb51.net/article/35230.htm .NET中包含了很多支持XML的类,这些类使得程序员使用XML编程就如同理解XML文件一样简单.在这篇文章中,我将给 ...
- Spring 系列: Spring 框架简介
Spring AOP 和 IOC 容器入门(转载) 在这由三部分组成的介绍 Spring 框架的系列文章的第一期中,将开始学习如何用 Spring 技术构建轻量级的.强壮的 J2EE 应用程序.dev ...


