Time of Update: 2018-12-05
Android 中SharedPreferences使用一、SharedPreferences使用1protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);SharedPreferences mPerferences =
Time of Update: 2018-12-05
Android 中的Theme和Style使用,還是比較簡單的。1、 首先在res/values/styles.xml的resource中定義三個樣式,分別為: <style name="TextView"> <item name="android:textSize">38sp</item> <item name="android:textColor">#128</item> <item
Time of Update: 2018-12-05
Android的Handler使用如何每隔一段時間進行一些操作呢,Handler就可以做到。 下面的Demo的功能為每隔3秒顯示MyItems數組中的不同資料。public class MainActivity extends Activity {private int count = 0;private static final String[] MyItems = { "Here is a Item1", "Here is a Item2", "Here is a Item3",
Time of Update: 2018-12-05
Android 中AlterDialog使用,AlterDialog的使用分為兩種,一種是直接使用,一種是自己設計一個Layout,然後當做Dialog顯示出來。1、定義兩個Button,一個用來顯示AlterDialog,一個顯示自訂的AlterDialog。private Button bt1;private Button bt2; 註冊事件protected void onCreate(Bundle savedInstanceState)
Time of Update: 2018-12-05
Android TahHost的使用,這裡採用繼承TabActivity的方法。這裡分別定製三個Tab,分別為american.xml, chinese.xml, japanese.xml三個Layout。american.xml檔案<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Time of Update: 2018-12-05
Android 中PopupWindow使用。PopupWindow會阻塞對話方塊,要在外部線程 或者 PopupWindow本身做退出才行。mypopWindow.xml的Layout設計如下。<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
Time of Update: 2018-12-05
項目的結構首先建立一個book_info.xml的xml檔案,結構如下:<?xml version="1.0" encoding="UTF-8"?><books> <catalog>Computer</catalog> <book> <country>USA</country> <title>Empire Burlesque</title>
Time of Update: 2018-12-05
Android中BroadcastReceiver使用分為動態註冊BroastcastReceiver ,靜態註冊BroastcastReceiver1、動態註冊BroastcastReceiver。定義BroadcastReceiver: private BroadcastReceiver bcr1 = new BroadcastReceiver() { @Overridepublic void onReceive(Context context, Intent
Time of Update: 2018-12-05
1、定義簡單的適配器形式。首先定義一個Layout為listviewitem.xml. 裡面有三個TextView。分別代表學號,姓名,班級。<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/cuslistViewItem"
Time of Update: 2018-12-05
Android Notication的使用private void sendNotification() {// TODO Auto-generated method stubNotificationManager manager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);Notification notification = new
Time of Update: 2018-12-05
Layout的設計,其實有我這裡直接拖了一個TabHost控制項,然後在每個Tab中放一個Button。檔案名稱為activity_tab_host.xml.<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
Time of Update: 2018-12-05
Android 自訂View為MyCustomView。在MyCustomView畫了一個Rect,顏色為Green,和一個為紅色的文字。public class MyCustomView extends View{ private Paint mPaint; private Context mContext; private static final String mString = "Hello world!"; public
Time of Update: 2018-12-05
Android程式運行效能最佳化 原文地址對於Android手機來說,由於Google全面開放多任務同時運行著Java這樣的解釋型語言導致對RAM的開銷很大,隨著Android平台的發展很多新手程式員在經驗等問題,會導致你的應用執行效率較低。針對於發布版應用應該注意以下幾點: 一、慎用Logcat輸出
Time of Update: 2018-12-05
Android 資源的使用一、dimension資源的使用Android中dimension單位有: px 像素 dp 密度 mm 毫米 pt 點 sp 刻度 in英寸dimension資源的定義<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">1
Time of Update: 2018-12-05
Android ExpandableListView的使用一、MainActivity要繼承ExpandableListActivity。效果是當單機ListView的子項是顯示另一個ListView。public class MainActivity extends ExpandableListActivity {private static final String NAME = "NAME";private static final String IS_EVEN =
Time of Update: 2018-12-05
Android中ExpandableList的使用2本文介紹Android中ExpandableList的使用,在前文的基礎上作了很多改進,增加了增加、刪除、回調等功能。圖中的 “第一行班組號: 1 軟體工程2班”是要顯示的資訊。先看: 首先定義一個含有ExpandableListView的Layout。還有一個是顯示的文本資訊。<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
Time of Update: 2018-12-05
Android 檔案操作操作時,要賦予相應的許可權: <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 下面是向檔案寫文本的代碼: private final static String PATH = "/sdcard/lin";private final static String FILENAME =
Time of Update: 2018-12-05
將android:screenOrientation="portrait",轉換橫屏豎屏無效,始終顯示豎屏。 <application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
Time of Update: 2018-12-05
Android中的TableLayout的簡單使用在Layout中加入TableLayout控制項。 <TableLayout android:id="@+id/myTableLayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="40dp"
Time of Update: 2018-12-05
Android 連絡人資訊的擷取public class MainActivity extends Activity {String id, name, phoneNumber, email;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);ContentResolver