Android初体验
上文提到使用genymotion来运行android项目,结果却是令人失望,我这边使用的是代理账户,尽管我在Setting中配置了代理,还是不能登录我注册的账户,郁闷,于是本文采用的是我自己的手机作为运行机子来运行的。
新建工程后,打开activiy_main.xml,在试图模式下,拖拉控件,效果确实不错。

在后台代码中绑定button事件尝试下,android的运行效果:
package com.example.administrator.myapplication2; import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.EditText;
import android.widget.CheckBox;
import android.widget.TextView;
import android.view.View; public class MainActivity extends ActionBarActivity { TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); textView=(TextView)findViewById(R.id.textView); // 第一种方式:
Button btnOk= (Button)findViewById(R.id.btnOk);
btnOk.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
String strTemp="Hello World!!!";
textView.setText(strTemp);
}
}); // 第二种使用Button的方法:
Button btnClick2= (Button)findViewById(R.id.btnClick2);
btnClick2.setOnClickListener(listener);
} Button.OnClickListener listener=new Button.OnClickListener(){
public void onClick(View v){
CheckBox checkBox= (CheckBox)findViewById(R.id.checkBox);
checkBox.setChecked(true);
}
}; public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
} @Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId(); //noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
} return super.onOptionsItemSelected(item);
}
}
浏览下activity_main.xml的代码:
<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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> <TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" /> <CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New CheckBox"
android:id="@+id/checkBox"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true" /> <ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:layout_below="@+id/checkBox"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UsingButtonWithFirstWay"
android:id="@+id/btnOk"
android:layout_marginTop="75dp"
android:layout_below="@+id/imageButton"
android:layout_toEndOf="@+id/textView" /> <Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="UsingButtonWithSecondWay"
android:id="@+id/btnClick2"
android:layout_below="@+id/btnOk"
android:layout_alignStart="@+id/btnOk"
android:layout_alignEnd="@+id/btnOk" /> </RelativeLayout>
Android初体验的更多相关文章
- Mono for Android—初体验之“电话拨号器”
1.Main.axml文件: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmln ...
- Visual Studio Emulator for Android 初体验
Visual Studio Emulator for Android已经推出一段时间了,但一直没有用过.前两天下载安装用了下,整体感觉比谷歌自带的模拟器强多了.Visual Studio Emulat ...
- android初体验——HelloWord
一.新建项目: 打开 eclipse ,选择File – New – Android Application Project 输入项目名称,程序名称,包名. 包名不能重复,它是项目的唯一标示,我理解为 ...
- Spring For Android初体验
Spring For Android是Spring框架的一个扩展,其主要目的在乎简化Android本地应用的开发,这其中包括了你可以使用该项目提供的 RestTemplate来为你的Android客户 ...
- Android初体验之Monkey和MonkeyRunner
原文地址https://blog.csdn.net/mad1989/article/details/38087737 Monkey 什么是Monkey Monkey是Android中的一个命令行工具, ...
- Android初体验-D3
1. UI界面布局. (即可用XML控制布局也可采用Java代码布局,不过在实际应用中是两者混合控制UI界面,为什么呢,因为XML适用于固定的不易改变的组件布局,Java程序控制常变的组件...其控制 ...
- Android开发学习之路--百度地图之初体验
手机都有gps和网络,通过gps或者网络可以定位到自己,然后通过百度,腾讯啊之类的地图可以显示我们的地理位置.这里学习下百度地图的使用.首先就是要申请开发者了,这个详细就不多讲了.http://dev ...
- Xamarin+Prism开发详解四:简单Mac OS 虚拟机安装方法与Visual Studio for Mac 初体验
Mac OS 虚拟机安装方法 最近把自己的电脑升级了一下SSD固态硬盘,总算是有容量安装Mac 虚拟机了!经过心碎的安装探索,尝试了国内外的各种安装方法,最后在youtube上找到了一个好方法. 简单 ...
- Xamarin.iOS开发初体验
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKwAAAA+CAIAAAA5/WfHAAAJrklEQVR4nO2c/VdTRxrH+wfdU84pW0
随机推荐
- Windows远程桌面连接Mac OS X
Windows远程桌面连接Mac OS X 第一步:Mac OS X 10.5 已经增加支持了由VNC Viewer访问的功能,设置如下: 系统偏好设置-共享-勾选“屏幕共享”,然后在电脑设置 ...
- PHP调用java的class
PHP调用java的class 转:http://hi.baidu.com/lei0827/blog/item/28439a4e923234ced1c86a18.html PHP调用java的cl ...
- HAProxy安装及初步使用
1.yum安装wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -ivh epel-r ...
- linux 输入java 出现中文乱码
http://jingyan.baidu.com/article/ab69b270de8b4f2ca7189f1d.html 1.查看当前linux的编码 没设置之前是:zh_CN.UTF_8 输入 ...
- vector 初始化所有方法
简介:vector可用于代替C中的数组,或者MFC中的CArray,从许多说明文档或者网上评论,一般一致认为应该多用vector,因为它的效率更高,而且具备很好的异常安全性.而且vector是STL推 ...
- java Semaphore
//Listing 6-4. Using a Counting Semaphore to Control Access to a Pool of Items import java.util.conc ...
- excel15个技巧
自动定时保存Excel中的文件 点击“工具”菜单“自动保存”项,设置自动保存文件夹的间隔时间.如果在“工具”菜单下没有“自动保存”菜单项,那么执行“工具”菜单下“加载宏…”选上“自动保存”,“确定”. ...
- cookie函数
function getcookie(){ var cookie={}; var all=document.cookie; if(all===""){ alert(2); retu ...
- asr,tts,vsr
http://max.book118.com/html/2014/0814/9432056.shtm ASR技术的基础主要是信号处理和概率模型. 信号处理技术 语音信号处理 谱分析 基于时间的 ...
- Qt 无边框窗体改变大小 完美实现(全部自己实现)
近期,做项目用到无边框窗体,令人蛋疼的是无边框窗体大小的改变要像右边框那样,上下左右四周,而且要流畅. 网上也找了些代码,发现居然还要连接到windows事件,这显然不合常理,后来自己新建了demo, ...