android開發中遇到的那些亂七八糟的方法、類

來源:互聯網
上載者:User

1.ComponentName

此類主要是擷取是包名Activity名,以及提轉到此Activity使用


        ntent.setComponent(componetName);
        startActivity(intent);


2.     startActivities(Intent[])
        startActivities(buildIntentsToViewsLists());
   我們經常用到的是startActivity(Intent),而startActivities(Intent[])的作用與之完全相同,
   無非就是將Intent[]中的三個Intent所指向的跳轉目標Activity從後至前依次添加到當前Activity棧中,如果大家在點擊完按鈕後用“Back”鍵返回,
   會發現返回的順序和Intent[]中的順序從後至前一致。

3.去除標題列
          requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉標題列
   //取消狀態列
          this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
          WindowManager.LayoutParams.FLAG_FULLSCREEN);

4.直接用色值給TextView上色
          Color.parseColor("FFFFFF"));(自己測試發現報錯)
          tv.setTextColor(Color.rgb(255, 255, 255)); 
          setTextColor(0xff737373); 

5.線程
          interrupt()方法能即可打斷正在執行的線程,如果此時線程正在sleep();打斷就會報錯
6.按back不退出程式返回案頭   
          Intent home = new Intent(Intent.ACTION_MAIN);   
          home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);   
          home.addCategory(Intent.CATEGORY_HOME);   
          startActivity(home); 

7.安裝SDK上的一個apk 

  public void installApk(File file) {Uri uri = Uri.fromFile(file);Intent intent = new Intent(Intent.ACTION_VIEW);intent.setDataAndType(uri, "application/vnd.android.package-archive");startActivity(intent);}

8.TextVIew文本中分段顯示不同顏色文本

  

editText2.setText(Html.fromHtml(  "<font color=#E61A6B>紅色代碼</font> "+ "<i><font color=#1111EE>藍色斜體代碼</font></i>"+"<u><i><font color=#1111EE>藍色斜體加粗體底線代碼</font></i></u>"));

很遺憾Html類不支援 設定字型的大小

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.