Time of Update: 2018-12-08
Android NDK中使用socket的整個過程分為以下幾部分:第一部分: 建立socket並綁定IP和連接埠複製代碼 代碼如下:#include <sys/select.h>#include <sys/socket.h>#include <arpa/inet.h>#define MAX_DATA_BUF_LEN 10240int sd = INVALID_SOCKET;sockaddr_in addr_org; // 發送端地址sd =
Time of Update: 2018-12-08
複製代碼 代碼如下:import java.text.SimpleDateFormat; SimpleDateFormat formatter = new SimpleDateFormat ("yyyy年MM月dd日 HH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());//擷取目前時間 String str =
Time of Update: 2018-12-08
有時候我們想在標準的Framework中添加自己的新的資源怎麼辦呢?辦法就是我們來嘗試下。通過Eclipse的聯絡,我們可以聯想到是否就是簡單的把字串放在res的各個檔案夾裡面。先來試試看,編譯,系統立即報錯。為什麼呢?它提示你利用make update-api這個命令來更新public.xml檔案或者把這個聲明稱hide類型。這個肯定不是我們想要的。所以方法有二:方法1:正常添加完資源後,執行make
Time of Update: 2018-12-08
Android中的TextView,本身就支援部分的Html格式標籤。這其中包括常用的字型大小顏色設定,文本連結等。使用起來也比較方便,只需要使用Html類轉換一下即可。比如:textView.setText(Html.fromHtml(str));一、實現TextView裡的文字有不同顏色[plain] 複製代碼 代碼如下:import android.text.Html; TextView t3 = (TextView) findViewById(R.id.text3); t3.
Time of Update: 2018-12-08
[java] 複製代碼 代碼如下:private void shutdown() { try { Process process = Runtime.getRuntime().exec("su"); DataOutputStream out = new DataOutputStream( process.getOutputStream());
Time of Update: 2018-12-08
原理: Android系統通過應用程式自行在系統中登記註冊事件(即Intent)來響應系統產生的各類訊息。 Android系統為應用程式管理功能提供了大量的API,通過配置Intent和permission來實現各種功能。 開機自啟動是通過 <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <category
Time of Update: 2018-12-08
首先用戶端從伺服器端擷取json資料1、利用HttpUrlConnection複製代碼 代碼如下:/** * 從指定的URL中擷取數組 * @param urlPath * @return * @throws Exception */ public static String readParse(String urlPath) throws Exception {
Time of Update: 2018-12-08
1. Adapter.getView() public View getView(int position, View convertView , ViewGroup parent){...} 這個方法就是用來獲得指定位置要顯示的View。官網解釋如下: Get a View that displays the data at the specified position in the data set. You can either create a View manually or
Time of Update: 2018-12-08
首先,ShapeDrawable構造的時候可以指定描畫的形狀,其次,可以通過shape.getPaint().setShader();指定Shader,shader可以接受一個圖片和matrix所以問題就順利的解決了:)具體實現如下:[java]複製代碼 代碼如下:float scale = 1.2f; int cx = 224; int cy = 357; int r = 200; // 指定形狀建立一個ShapeDrawable ShapeDrawable shape=new
Time of Update: 2018-12-08
網上關於這個方面的文章也不少,基本的思路是線程+緩衝來解決。下面提出一些最佳化: 1、採用線程池 2、記憶體緩衝+檔案快取 3、記憶體緩衝中網上很多是採用SoftReference來防止堆溢出,這兒嚴格限制只能使用最大JVM記憶體的1/4 4、對下載的圖片進行按比例縮放,以減少記憶體的消耗 具體的代碼裡面說明。先放上記憶體緩衝類的代碼MemoryCache.java: 複製代碼 代碼如下:<SPAN style="FONT-SIZE:
Time of Update: 2018-12-08
Android中很重要的一個機制就是線程+訊息,當然線程並不是android專屬的,下面,簡單的說說使用線程的時候應該注意的地方我們採用最簡單的方法來建立一個android的線程+訊息的例子1.Thread + Handler[java]複製代碼 代碼如下:package com.example.test_thread; import android.app.Activity; import android.os.Bundle; import android.os.Handler;
Time of Update: 2018-12-08
先看:首先,你得寫一個類我們命名為CornerListView[java]複製代碼 代碼如下:/** * 圓角ListView樣本 * @Description: 圓角ListView樣本 * @FileName: CornerListView.java */ public class CornerListView extends ListView { public CornerListView(Context context) { super(context);
Time of Update: 2018-12-08
Activity 跳轉 都知道用startActivity(Intent)但是如果下面情況呢?Activity1 跳轉到 Activity2 但是還需要在Activity2 再回到 Activity1呢? 可能有人說: 那我在Activity2 再使用 startActivity() 不就可以了 是的 但是 startActivityForResult() 能夠直接完成這項工作[樣本]Activity1: 有2個EditText 用於接收使用者輸入的2個字串 要求把這2個字串串連起來
Time of Update: 2018-12-08
複製代碼 代碼如下: Configuration config = getResources().getConfiguration(); if (config.orientation == Configuration.ORIENTATION_LANDSCAPE){ //橫屏,比如 480x320 }else if(config.orientation == Configuration.ORIENTATION_PORTRAIT){ //豎屏 ,標準模式 320x480 }else
Time of Update: 2018-12-08
在Android中intent傳遞對象主要有2種方式分別是,Bundle.putSerializable(Key,Object)和Bundle.putParcelable(Key, Object);當然這些Object是有一定的條件的,前者是實現了Serializable介面,而後者是實現了Parcelable介面,以下是我為大家做的一個執行個體 首先我們建立一個工程項目命名為:ObjectTestDemo 然後我們再修改main.xml布局檔案,主要增加2個按鈕view
Time of Update: 2018-12-08
android實現開機自啟動可能是移動作業系統中最簡單的了,我們只需要監聽一個開機啟動的Broadcast(廣播)即可。首先寫一個Receiver(即廣播監聽器),繼承BroadcastReceiver,如下所示: view source print?複製代碼 代碼如下: public class BootReceiver extends BroadcastReceiver { private PendingIntent mAlarmSender; @Override
Time of Update: 2018-12-08
Android的Bitmap和J2ME的Image比較類似。 如果我想從resource裡讀入一個圖片,然後在這個圖片上draw一點自己的資訊,比如文字。 再畫到螢幕上怎麼做呢? J2ME裡只要Image.getGraphic() 拿到 Graphic的對象就可以想draw什麼就draw什麼了。 那麼Android裡怎麼實現呢? Java 代碼複製代碼 代碼如下: Bitmap img = Bitmap.createBitmap(width, height,
Time of Update: 2018-12-08
後台代碼複製代碼 代碼如下: private void ChangeView() { ly.removeAllViews(); LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.grid,null); GridView
Time of Update: 2018-12-08
在《Android
Time of Update: 2018-12-08
1.