android開發的一些技巧

來源:互聯網
上載者:User

 

設定url

設定是否當文本為 URL連結、Email 、電話號碼、Map 時,文本顯示為可點擊的連結。

         android:autoLink
   可選值:none / web / email / phone / map / all 

---------------------------------------------華麗的分割線---------------------------------------------

屏蔽IME鍵盤的方法

方法一:


androidminifest檔案當中,在需要屏蔽IME的Activity裡添加屬性:

 android:windowSoftInputMode="adjustPan|stateHidden" 。


方法二:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);

//myEdit是需要禁止自動彈出軟鍵盤的EditText對象。
imm.hideSoftInputFromWindow(myEdit.getWindowToken(), 0);

 

---------------------------------------------華麗的分割線---------------------------------------------

EditView插入圖片

直接通過反射技術從R.drawable類中獲得映像資源ID的方法。這種方法的好處是一但映像資源非常多時,

可以不需要在數組中挨個定義就可以獲得任意的映像資源ID。使用android.text.style.ImageSpan類來直接插入映像。

下面來看看具體的實現代碼:

public void onClick_RandomFace(View view){            //  隨機產生1至9的整數    int randomId = 1 + new Random().nextInt(9);    try    {        //  根據隨機產生的1至9的整數從R.drawable類中獲得相應資源ID(靜態變數)的Field對象        Field field = R.drawable.class.getDeclaredField("face" + randomId);        //  獲得資源ID的值,也就是靜態變數的值        int resourceId = Integer.parseInt(field.get(null).toString());        //  根據資源ID獲得資源映像的Bitmap對象        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), resourceId);        //  根據Bitmap對象建立ImageSpan對象        ImageSpan imageSpan = new ImageSpan(this, bitmap);        //  建立一個SpannableString對象,以便插入用ImageSpan對象封裝的映像        SpannableString spannableString = new SpannableString("face");        //  用ImageSpan對象替換face        spannableString.setSpan(imageSpan, 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);        //  將隨機獲得的映像追加到EditText控制項的最後        edittext.append(spannableString);    }    catch (Exception e)    {    }}

還有一種方法 未經驗證

在xml中很簡單 只要在veditView中設定屬性Drawable{Right | Left | Top | Bottom} 在設定中可以使用 EditText text = (EditText)findViewById(R.id.text); text.setCompoundDrawables(null, null, getResources().getDrawable(R.drawable.check_box), null);
 

ListView中有CheckBox onItemClick事件不能觸發

item的根layout

 android:descendantFocusability="blocksDescendants"

android:focusable="false"

android:focusableInTouchMode="false"


checkbox裡面設定這兩個屬性

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.