Time of Update: 2018-12-08
布局檔案:res/layout/activity_my.xml複製代碼 代碼如下:[html] <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/LinearLayout" android:layout_width="fill_parent"
Time of Update: 2018-12-08
在java中可有兩種方式實現多線程,一種是繼承Thread類,一種是實現Runnable介面;Thread類是在java.lang包中定義的。一個類只要繼承了Thread類同時覆寫了本類中的run()方法就可以實現多線程操作了,但是一個類只能繼承一個父類,這是此方法的局限。下面看例子:複製代碼 代碼如下:package org.thread.demo; class MyThread extends Thread{ private String name; public
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
去掉標題列:requestWindowFeature(Window.FEATURE_NO_TITLE);API上是這麼說的:int FEATURE_NO_TITLE Flag for the "no title" feature, turning off the title at the top of the
Time of Update: 2018-12-08
需要引入ksoap2-android-assembly-2.5.2-jar-with-dependencies.jar複製代碼 代碼如下: //WebService的命名空間 static final String namespace = "http://impl.service.suncreate.com"; //伺服器發布的url static final String url =
Time of Update: 2018-12-08
複製代碼 代碼如下:package com.aslibra.test; import android.app.Activity; import android.graphics.Rect; import android.os.Bundle; import android.util.Log; import android.view.Window; import android.widget.ImageView; public class test extends Activity {
Time of Update: 2018-12-08
複製代碼 代碼如下:public class PageWidget extends View { private Bitmap foreImage; private Bitmap bgImage; private PointF touchPt; private int screenWidth; private int screenHeight; private GradientDrawable shadowDrawableRL; private
Time of Update: 2018-12-08
當螢幕變為橫屏的時候,系統會重新呼叫當前Activity的OnCreate方法,你可以把以下方法放在你的OnCreate中來檢查當前的方向,然後可以讓你的SetContentView來載入不同的Layout xml.複製代碼 代碼如下:if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {Log.i("info", "landscape");}else if
Time of Update: 2018-12-08
1. UiObejct.getFromParent()的用法:從這個名字就知道,就是從當前對象的父物件中尋找想要的子物件,該子物件和當前對象應該是同一層級。如所示:Max inactivity before lock是已知條件,4 minutes是我想動態擷取的內容。那應該怎麼做呢?先看看結構:TableLayout(curent index is 2) - TableRow(has several indexes) - TextView(has 2
Time of Update: 2018-12-08
android:gravity:設定的是控制項自身上面的內容位置android:layout_gravity:設定控制項本身相對於父控制項的顯示位置。看下如下程式碼片段複製代碼 代碼如下:<?xml version="1.0" encoding="utf-8"?><!-- android:gravity設定了按鈕上面的文字的顯示位置,而android:layout_gravity設定了按鈕在布局中的顯示位置。--><LinearLayout
Time of Update: 2018-12-08
很多時候我們開發的軟體需要向使用者提供軟體參數設定功能,例如我們常用的QQ,使用者可以設定是否允許陌生人添加自己為好友。對於軟體配置參數的儲存,如果是window軟體通常我們會採用ini檔案進行儲存,如果是 j2se應用,我們會採用properties屬性檔案或者xml進行儲存。如果是Android應用,我們最適合採用什麼方式儲存軟體配置參數呢?Android 平台給我們提供了一個SharedPreferences類,它是一個輕量級的儲存類,特別適合用於儲存軟體配置參數。使用
Time of Update: 2018-12-08
資料存放區與訪問常用方式:檔案SharedPreferences(偏好參數設定)SQLite資料庫內容提供者(Content provider)網路Activity(Context)Context.getCacheDir()方法用於擷取/data/data/<package name>/cache目錄Context.getFilesDir()方法用於擷取/data/data/<package
Time of Update: 2018-12-08
Content Provider:一個組件,必須放在應用的主包或應用的子包之下;組件的配置需要在資訊清單檔中進行配置;content provider需要在application節點中進行配置;內容提供者在應用中的作用是對外共用資料(任意類型的資料)使用的,別的程式可以對資料進行CRUD,如通訊錄;如果採用檔案的方式對外共用資料,會因為檔案的類型不同而需要使用不同的api訪問方式導致訪問繁雜,而內容提供者提供了統一的api對資料進行操作;<provider android:name=".
Time of Update: 2018-12-08
SharedPreferences用於在開發軟體的時候提供軟體參數設定,其背後使用的是xml檔案存放資料,檔案儲存在/data/data/<package name>/shared_prefs目錄下;複製代碼 代碼如下: public void savePreferences(String name, Integer age) {-->> get SharedPreferences SharedPreferences preferences =
Time of Update: 2018-12-08
Intent:當找到與設定的Intent限制相同的Activity時候通過startActivity()就會啟動該Activity電話播號器:intent.setAction("android.intent.action.CALL");intent.addCategory("android.intent.category.DEFAULT");intent.setData(Uri.parse("tel:" +
Time of Update: 2018-12-08
首先,建立一個用於顯示一個item的layout,名為item.xml複製代碼 代碼如下:<?xml version="1.0" encoding="utf-8"?><LinearLayout
Time of Update: 2018-12-08
TabWidget類似於Android 中查看電話薄的介面,通過多個標籤切換顯示不同內容。要實現這一效果,首先要瞭解TabHost,它是一個用來存放多個Tab標籤的容器。每一個Tab都可以對應自己的布局,比如,電話薄中的Tab布局就是一個List的線性布局了。 要使用TabHost,首先需要通過getTabHost方法來擷取TabHost的對象,然後通過addTab方法來向TabHost中添加
Time of Update: 2018-12-08
複製代碼 代碼如下:<SPAN style="FONT-SIZE: 18px">private void alertScreenDialog() { DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); String optStr = "手機螢幕解析度為: "+dm.widthPixels+" x "+dm.heightPixels;
Time of Update: 2018-12-08
複製代碼 代碼如下:package com.demos; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class GetScreenActivity extends Activity { private Button
Time of Update: 2018-12-08
提示:org.xmlpull.v1.XmlPullParserException: PI must not start with xml (position:unknown @1:5 in java.io.InputStreamReader@47ec2770)org.xml.sax.SAXParseException: PI must not start with xml (position:unknown xm@3:5 in