Time of Update: 2018-12-08
廢話少說,直接,有圖有真相。這兩個工具列全是用布局來實現的。底部工具列布局代碼:代碼複製代碼 代碼如下: < xmlns:android="http://schemas.android.com/apk/res/android" android:background="@drawable/bottom" android:layout_width="fill_parent" android:layout_height="wrap_content" >
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
布局檔案: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
這是個很簡單的問題,但每次隔一段時間後使用起來總是會出點亂子。這裡記錄下Logcat的步驟:1,在Activity裡申明tag變數(名字其實是隨便的,如下:private static final String tag="yan";2,需要使用logcat輸出資訊時:Log.i(tag, "螢幕寬度:"+display.getWidth()+" 螢幕高度:"+display.getHeight());3, 雙擊Logcat,點擊“+”號add a new logcat
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實現開機自啟動可能是移動作業系統中最簡單的了,我們只需要監聽一個開機啟動的Broadcast(廣播)即可。首先寫一個Receiver(即廣播監聽器),繼承BroadcastReceiver,如下所示: view source print?複製代碼 代碼如下: public class BootReceiver extends BroadcastReceiver { private PendingIntent mAlarmSender; @Override
Time of Update: 2018-12-08
舉個例子我現在要從A介面跳轉到B介面或者C介面 這樣的話 我就需要寫2個Intent如果你還要涉及的傳值的話 你的Intent就要寫兩遍添加值的方法 那麼 如果我用1個Bundle 直接把值先存裡邊 然後再存到Intent中 不就更簡潔嗎?另外一個例子如果我現在有Activity A ,B ,C;現在我要把值通過A經過B傳給C你怎麼傳 如果用Intent的話 A-B先寫一遍 再在B中都取出來 然後在把值塞到Intent中 再跳到C 累嗎?如果我在A中用了 Bundle 的話
Time of Update: 2018-12-08
繪製圓環其實很簡單,有大概以下三種思路. 這裡先說網上提到的一種方法。思路是先繪製內圓,然後繪製圓環(圓環的寬度就是paint設定的paint.setStrokeWidth的寬度),最後繪製外圓。請看核心源碼:複製代碼 代碼如下:<SPAN xmlns="http://www.w3.org/1999/xhtml">package yan.guoqi.rectphoto;import android.content.Context;import
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
1.對包名的判斷,異常則說明不存在:複製代碼 代碼如下: try { PackageManager pm = getPackageManager(); pm.getPackageInfo("com.org", PackageManager.GET_ACTIVITIES); } catch (NameNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace();
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
如何在Android上擷取本機電話號碼,目前Android上提供了一個API可以讀取早期SIM卡上固化的號碼,複製代碼 代碼如下:private String getPhoneNumber(){ TelephonyManager mTelephonyMgr; mTelephonyMgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); return
Time of Update: 2018-12-08
如果你對Android系統內建的UI控制項感覺不夠滿意,可以嘗試下自訂控制項,我們就以Button為例,很早以前Android123就寫到過Android Button按鈕控制項美化方法裡面提到了xml的selector構造。當然除了使用drawable這樣的圖片外今天Android開發網談下自訂圖形shape的方法,對於Button控制項Android上支援以下幾種屬性shape、gradient、stroke、corners等。複製代碼
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
複製代碼 代碼如下:findViewById(R.id.myButton).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { // Do stuff } }); 採用上述方法添加Listener有個缺點就是如果控制項太多的話,Listener數量也會增多,因此,可以採用如下的小竅門減少Listener的數量:複製代碼
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
當螢幕變為橫屏的時候,系統會重新呼叫當前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
Android