編輯:關於android開發
工具是:JDK環境配置+SDK+ADT工具
一、Activity 主要作用:
1、用戶與應用程序的接口
2、控件的容器
二、創建Activity要點:(在src中的目錄下包裡)
1、一個Activity就是一個類,要繼承android自身的一個類
2、需要復寫Oncreate方法,第一個運行的Activity中調用oncreate來調用
3、Activity是一個組件,在Androidmanifest.xml中的intent-filter,在哪一個Activity中配置了intent-filter就是android中第一個啟動的Activity
4、Activity中本身沒有內容,在Activity中添加必要de組件,Textview,button,下拉菜單。單選按鈕,多選按鈕。。。。
三、layou中的布局文件
1、LinearLayout(線性布局)中的android:orientation=“vertical”//垂直
android:layout_width="fill_parent"//寬度
android:layout_height="fill_parent"//高度
2、<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_parent"
>
3 、調用Activity中可以用findviewbyid方法findviewbyid(R.id.自己去的名字)
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);//父類中Oncreate方法
setContentView(R.layout.activity_main);//設置
//得到控件用findviewbyid
TextView mytextView=(TextView)findViewById(R.id.mytextView);
Button mybutton=(Button)findViewById(R.id.mybutton);
mytextView.setText("我的第一個textview");
mybutton.setText("我的第一個button"+"\n"+"換行");
每一個程序員從hello world開始
四、acticity和intent
(一)內容:
1、多個activit之間的關系
2、intent的基本作用
3、在一個activity中方啟動另外一個activity
4、在使用的intent在activity中使用intent進行數據的傳遞的基本方法
(二)多個activity之間的關系
可以是同一個程序中的activity之間跳轉,也可以是不同的應用中的activity
由intent啟動非常重要的作用。
(三)intent的基本作用://intent是一個對象,翻譯成中中文叫做意圖,就像一個請求。
1、component name //啟動哪一個activity,根據intent對象component name信息,啟動哪一個組件。
2、action//官方解釋是指定另外一個activity做什麼
3、data//從這個activity到另外一個activity中傳遞時intent中的data。
4、category//
5、extras//額外的信息,鍵值對,在intent中
6、flags
(三)intent的基本使用方法
用startactivity方法,調用另外一個actcity,我們可以在intent中存放一些就extra中鍵值對,在另外一個activity中顯示出來。
在activity中使用button,得到button按鈕,通過findviewbyid方法,把button生成私有變量。
建立第二個activity,anotheractivity,繼承Activity,復寫oncreate(右鍵,source中的override/implemen,)
創建第二個布局文件,加上一個textview,在anotheractivity中獲得textview。最終的要的是設置一個setContentView(R.layout.other),這個activity使用這樣的一個布局。
在Mainactivity中獲得main.xml中的button中,首先設計一個監聽器,把監聽器捆綁在按鈕上。
class MyButtonListener implements OnClickListener//MyButtonListener內部類r
{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent=new Intent();//生成一個Intent對象 intent相當於一個請求
intent.putExtra("testIntent","123");//鍵值對名稱就叫成testIntent,值是123
intent.setClass(MainActivity.this,anotheractivity.class);//從MainActivity調到anotheractivity
MainActivity.this.startActivity(intent);//調用當前activity中的startActivity方法
}
捆綁在命令按鈕上:
啟動後,點擊按鈕後發現一個異常
發現在AndroidMainfest.xml中忘記了注冊第二個anotheractivity,所以出現異常。bug
<activity android:name="anotheractivity"
android:label="@string/other"/>
在anotheractivity中寫上
//把值取出來
Intent intent=getIntent();//getintent方法得到mainactivity中的intent
String value=intent.getStringExtra("testIntent");//getStringExtra方法把鍵傳進來
mytextview=(TextView)findViewById(R.id.mytextview);
mytextview.setText(value);
運行成功:
以上是跳轉到另外一個activity。
在兩個activity中傳遞數據的方法,傳的值是123。
使用Intent發送消息
從一個組件到另外一個組件
發短信是我們經常使用的功能,發短信時android系統自帶的,這個兩個應用程序中兩個activity,不妨礙intent傳遞數據。
在anotheractivity中加入一段代碼,已經不是之前那個activity,而是一個發短信的activity。
package com.helloworld;
import android.support.v7.app.ActionBarActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;
import android.widget.TextView;
public class anotheractivity extends ActionBarActivity {
private TextView mytextview=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.another);
//把值取出來
/*Intent intent=getIntent();//getintent方法
String value=intent.getStringExtra("testIntent");
mytextview=(TextView)findViewById(R.id.mytextview);
mytextview.setText(value);*/
Uri uri=Uri.parse("smsto://0800000123");
Intent intent=new Intent(Intent.ACTION_SENDTO,uri);//操作系統自己的攜帶的ACTION_SENDTO
intent.putExtra("sms_body","The SMS Text");
startActivity(intent);
}
}
運行命令按鈕之後:
Android Design支持庫TabLayout打造仿網易新聞Tab標簽效果(三十七)
Android Design支持庫TabLayout打造仿網易新聞Tab標簽效果(三十七) (一).前言: 仿36Kr客戶端開發過程中,因為他們網站上
android插件開發-就是你了!啟動吧!插件的activity(一)
android插件開發-就是你了!啟動吧!插件的activity(一) 通過之前的例子例子,我們學習了如何尋找hook點,並且做一些非常無聊的事情。
ListView中響應item的點擊事件並且刷新界面,listviewitem
ListView中響應item的點擊事件並且刷新界面,listviewitem---恢復內容開始--- 最近在在實現listview功能中遇到了這個問題: 點擊事件寫在了
Android 環境搭建 以及 第一個android 程序的編寫,搭建android
Android 環境搭建 以及 第一個android 程序的編寫,搭建androidAndroid 環境搭建 (1)所需材料 eclipse 、ADT 、SDK 下載地址