圓角PopupWindow對話框和圓角EditText_第1頁
圓角PopupWindow對話框和圓角EditText_第2頁
圓角PopupWindow對話框和圓角EditText_第3頁
圓角PopupWindow對話框和圓角EditText_第4頁
圓角PopupWindow對話框和圓角EditText_第5頁
已閱讀5頁,還剩5頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、-作者xxxx-日期xxxx圓角PopupWindow對話框和圓角EditText【精品文檔】圓角PopupWindow對話框和圓角EditText Android默認(rèn)的PopupWindow和EditText的外觀是矩形框,看起來不是太好,本示例通過設(shè)置布局View的背景和PopupWindowd對象的背景,實現(xiàn)有白色圓角邊框的對話框效果和圓角文字編輯框。代碼如下(關(guān)鍵部分是背景布局XML):對話框彈出效果圖:Java代碼 1. package ; 2.3. import ; 4. import ; 5. import ; 6. import ; 7. import ; 8. import

2、; 9. import ; 10. import ; 11. import ; 12. import ; 13. import ; 14. import ; 15.16.17. public class RoundCorner extends Activity 18.19. Button mButton; 20.21. Override 22. public void onCreate(Bundle savedInstanceState) 23. (savedInstanceState); 24. setContentView(); 25.26. / 定義按鈕 27. mButton = (B

3、utton) (R.id.Button01); 28. (new ClickEvent(); 29.30. / 兩個圓角文字編輯框 31. EditText et1 = (EditText) (R.id.roundedtext1); 32. EditText et2 = (EditText) (R.id.roundedtext2); 33. et1.setInputType(); 34. et2.setInputType(); /不顯示軟鍵盤 35.36. 37.38. / 處理按鍵事件 39. class ClickEvent implements OnClickListener 40. O

4、verride 41. public void onClick(View v) 42. if (v = mButton) 43. showRoundCornerDialog(, (R.id.Button01); 44. 45. 46. 47.48. / 顯示圓角對話框 49. public void showRoundCornerDialog(Context context, View parent) 50. LayoutInflater inflater = (LayoutInflater) (); 51.52. / 獲取圓角對話框布局View,背景設(shè)為圓角 53. final View d

5、ialogView = (, null, false); 54. dialogView.setBackgroundResource(R.drawable.rounded_corners_view); 55.56. / 創(chuàng)建彈出對話框,設(shè)置彈出對話框的背景為圓角 57. final PopupWindow pw = new PopupWindow(dialogView, 300, , true); 58. pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_pop); 59.60. /注:上

6、面的設(shè)背景操作為重點部分,可以自行注釋掉其中一個或兩個設(shè)背景操作,查看對話框效果 61. /注:上面的設(shè)背景操作為重點部分,可以自行注釋掉其中一個或兩個設(shè)背景操作,查看對話框效果 62.63. final EditText edtUsername = (EditText) (); 64. final EditText edtPassword = (EditText) (); 65. (用戶名.); / 設(shè)置提示語 66. (密碼.); / 設(shè)置提示語 67.68. / OK按鈕及其處理事件 69. Button btnOK = (Button) (); 70. (new OnClickList

7、ener() 71. Override 72. public void onClick(View v) 73. / 設(shè)置文本框內(nèi)容 74. (username); 75. (password); 76. 77. ); 78.79. / Cancel按鈕及其處理事件 80. Button btnCancel = (Button) (); 81. (new OnClickListener() 82. Override 83. public void onClick(View v) 84. ();/ 關(guān)閉 85. 86. ); 87.88. / 顯示RoundCorner對話框 89. (paren

8、t, , 0, 0); 90. 91.92. package com.test;import android.app.Activity;import android.content.Context;import android.os.Bundle;import android.text.InputType;import android.view.Gravity;import android.view.LayoutInflater;import android.view.View;import android.view.View.OnClickListener;import android.wi

9、dget.Button;import android.widget.EditText;import android.widget.PopupWindow;import android.widget.LinearLayout.LayoutParams;public class RoundCorner extends Activity Button mButton; Overridepublic void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.ma

10、in);/ 定義按鈕mButton = (Button) this.findViewById(R.id.Button01);mButton.setOnClickListener(new ClickEvent();/ 兩個圓角文字編輯框EditText et1 = (EditText) this.findViewById(R.id.roundedtext1);EditText et2 = (EditText) this.findViewById(R.id.roundedtext2);et1.setInputType(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);e

11、t2.setInputType(InputType.TYPE_NULL); /不顯示軟鍵盤/ 處理按鍵事件class ClickEvent implements OnClickListener Overridepublic void onClick(View v) if (v = mButton) showRoundCornerDialog(RoundCorner.this, RoundCorner.this.findViewById(R.id.Button01);/ 顯示圓角對話框public void showRoundCornerDialog(Context context, View

12、parent) LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);/ 獲取圓角對話框布局View,背景設(shè)為圓角final View dialogView = inflater.inflate(R.layout.popupwindow, null, false);dialogView.setBackgroundResource(R.drawable.rounded_corners_view); / 創(chuàng)建彈出對話框,設(shè)置彈出對話框的背景為圓角 fi

13、nal PopupWindow pw = new PopupWindow(dialogView, 300, LayoutParams.WRAP_CONTENT, true);pw.setBackgroundDrawable(getResources().getDrawable(R.drawable.rounded_corners_pop);/注:上面的設(shè)背景操作為重點部分,可以自行注釋掉其中一個或兩個設(shè)背景操作,查看對話框效果/注:上面的設(shè)背景操作為重點部分,可以自行注釋掉其中一個或兩個設(shè)背景操作,查看對話框效果final EditText edtUsername = (EditText) d

14、ialogView.findViewById(R.id.username_edit);final EditText edtPassword = (EditText) dialogView.findViewById(R.id.password_edit);edtUsername.setHint(用戶名.); / 設(shè)置提示語edtPassword.setHint(密碼.); / 設(shè)置提示語/ OK按鈕及其處理事件Button btnOK = (Button) dialogView.findViewById(R.id.BtnOK);btnOK.setOnClickListener(new OnCli

15、ckListener() Overridepublic void onClick(View v) / 設(shè)置文本框內(nèi)容edtUsername.setText(username);edtPassword.setText(password););/ Cancel按鈕及其處理事件Button btnCancel = (Button) dialogView.findViewById(R.id.BtnCancel);btnCancel.setOnClickListener(new OnClickListener() Overridepublic void onClick(View v) pw.dismiss();/ 關(guān)閉);/ 顯示RoundCorner對話框pw.showAtLocation(parent, Gravity.CENTER|Gravity.BOTTOM, 0, 0);1,圓角對話框的背景布局文件XML。PopupWindow的背景布局文件Java代碼 1. 2. 3. 4.5. 6.7. 8.9. 11. shape xmlns:android=Java代碼 1. 2. 3. 4.5. 6.7. 8.9. 11. shape xmlns:android=2,圓角文字編輯框的三個布局XML文件Java代碼 1. 2. 3. 7. 11. 1

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論