Time of Update: 2018-12-04
這次主要是使用android系統內建控制項ViewFlipper 結合手勢和動畫實現滾動效果,類似於軟體協助效果:主要代碼:package com.pioneersoft.systemhelp;import java.util.HashMap;import org.apache.http.impl.client.TunnelRefusedException;import android.app.Activity;import android.content.Context;import
Time of Update: 2018-12-04
本文截選自《Android開發權威指南》 Android
Time of Update: 2018-12-04
搜尋指定檔案:public String searchFile(String filename){String res="";File[] files=new File("/sdcard").listFiles();for(File f:files){if(f.isDirectory())searchFile(f.getName());elseif(f.getName().indexOf(filename)>=0)res+=f.getPath()+"\n";}if(res.equals("
Time of Update: 2018-12-04
android應用可以通過android:theme設定 系統主題•android:theme="@android:style/Theme.Dialog" 將一個Activity顯示為能話框模式•android:theme="@android:style/Theme.NoTitleBar" 不顯示應用程式標題欄•android:theme="@android:style/Theme.NoTitleBar.Fullscreen" 不顯示應用程式標題欄,並全屏•android:theme="
Time of Update: 2018-12-04
在檢測應用程式是否需要升級時,首先應該擷取其版本號碼與伺服器端進行比較進行判斷是否升級Android有兩個版本號碼標識,分別為:versionCode,(整數值代表),versionName(字串代表)具體方法如下:public static int getVerCode(Context context) { int verCode = -1; try { verCode =
Time of Update: 2018-12-04
Android中設定螢幕全屏兩種方法:方法一代碼設定在Activity oncreate()方法中//隱去電池等表徵圖和一切修飾部分(狀態列部分) this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 隱去標題列(程式的名字)
Time of Update: 2018-12-04
程式想告訴Android系統自己能夠響應和處理哪些Intent,那麼就需要用到IntentFilter對象,IntentFilter對象負責過濾掉組件能夠處理的Intent請求,隱式Intent(Explicit Intents)和Intent Filter(Implicit
Time of Update: 2018-12-04
實際開發中可能會要確定螢幕朝向以防止布局受到影響在代碼中設定//強製為橫屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); //強製為豎屏 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); 在AndroidManifest.xml 中設定設定強制橫屏<activity
Time of Update: 2018-12-04
1,調web瀏覽器Uri myBlogUri = Uri.parse("http://www.soqi.cc");returnIt = new Intent(Intent.ACTION_VIEW, myBlogUri);2,地圖Uri mapUri = Uri.parse("geo:38.899533,-77.036476");returnIt = new Intent(Intent.ACTION_VIEW, mapUri);3,調撥打到電話介面Uri telUri =
Time of Update: 2018-12-04
Android中menu可分為兩種,分別為options menu(menu鍵產生), context menu(長按螢幕產生)下面舉個例子;1,options menu(menu鍵產生),@Overridepublic boolean onCreateOptionsMenu(Menu menu) {m=menu;menu.add(0, Menu.FIRST, 0, "1st");menu.add(0, Menu.FIRST+1, 0, "2st");menu.add(0,
Time of Update: 2018-12-04
最近研究了一下Activity的幾種啟動模式,總結如下:四種啟動模式如下:“standard” (預設)“singleTop”“singleTask”“singleInstance”standard 每次都會建立,每個Task都可以有,且每個Task都可以有多個執行個體(每個Task都可以有,且可以有多個)singleTop 當前執行個體如果在棧頂,就不建立執行個體,調用其OnNewIntent。
Time of Update: 2018-12-04
在Android中不支援直接載入gif格式的圖片,只能通過輔助類Movie實現,具體方法如下;public class DrawMusicNote extends View {private Movie mMovie;private long mMovieStart;//Set to false to use decodeByteArrayprivate static final boolean DECODE_STREAM = true;public DrawMusicNote(Context
Time of Update: 2018-12-04
最近在開發中涉及到了動態指定螢幕朝向,總結如下:Activity螢幕屬性有以下幾種: ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE,//指定橫屏 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT,//指定豎屏ActivityInfo.SCREEN_ORIENTATION_USER,//根據使用者朝向ActivityInfo.SCREEN_ORIENTATION_NOSENSOR,//不受重力影響
Time of Update: 2018-12-04
在Android中根據檔案位置的不同,可分為四種檔案讀取方式,具體如下;//方法:從resource中的raw檔案夾中擷取檔案並讀取資料,注意:只能讀取不能寫入資料 public String getFromRaw(int fileId) { InputStream in = null; String result = ""; ByteArrayOutputStream baos=null; try { // 擷取Resources資源檔流 in =
Time of Update: 2018-12-04
擷取狀態列和標題列的高度擷取狀態列高度: getWindowVisibleDisplayFrame方法可以擷取到程式顯示的地區,包括標題列,但不包括狀態列。 於是,我們就可以算出狀態列的高度了。Rect frame = new Rect(); getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight =
Time of Update: 2018-12-04
最近項目用到截屏功能,經過尋找資料,總結如下:方法一:/** * 簡易截屏方法 * @param v視圖 * @param filePath 儲存路徑 */ private void getScreenHot(View v, String filePath) { try { Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight()
Time of Update: 2018-12-04
當android的系統啟動的時候,系統會自動掃描sdcard內的檔案,並把獲得的資訊儲存在一個系統資料庫中,程式想要訪問系統檔案資訊,就是對檔案資料庫中進行的,而不是直接去sdcard中取。但是,如果系統在不重新啟動情況下,檔案資料庫資訊是不會更新的,這時就需要手動重新整理檔案系統了。其實質是發送一廣播語音總機系統進行檔案重新整理而已,具體如下;private void scanSdCard(){ IntentFilter intentfilter = new
Time of Update: 2018-12-04
Service是android四大組件中與Activity最相似的組件,都可以代表可執行檔程式。 Service與Activity的區別在於: (1)、Service一直在後台運行,沒有使用者介面。 (2)、一旦service被啟動之後,就跟Activity一樣。有自己的生命週期。所以可以沒有Activity。 開發service需要兩個步驟: (1)、定義一個繼承service的子類 (2)、在AndroidManifest.xml中配置該Service
Time of Update: 2018-12-04
最近在做項目,遇到一個比較頭疼的問題,問題是需要對使用者的輸入進行時時監聽,而大部分使用者的輸入是通過軟鍵盤來完成的,而Android平台好象沒有專門的對此監控事件,那該怎麼辦呢?最終解決辦法就是通過EditText和TextWatcher類來輔助監聽。具體做法如下:private class TextMonitor implements TextWatcher{ @Overridepublic void beforeTextChanged(CharSequence s, int start,
Time of Update: 2018-12-04
最近,看了api中例子程式定時自啟動,整理了一下共分享給大家;首先,建立AutouStartActivity類package com.start.app;import android.app.Activity;import android.app.AlarmManager;import android.app.PendingIntent;import android.content.Context;import android.content.Intent;import