編輯:關於android開發
在Android開發中,我們經常會需要在Android界面上彈出一些對話框,比如詢問用戶或者讓用戶選擇。這些功能我們叫它Android Dialog對話框,AlertDialog實現方法為建造者模式。AlertDialog中定義的一些對話框往往無法滿足我們關於對話框的需求,這時我們就需要通過自定義對話框VIEW來實現需求,這裡我自定義一個登陸的提示對話框,效果圖顯示如下:
Layout(alertdialog自定義登陸按鈕)界面代碼:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <Button 6 android:text="自定義登陸" 7 android:layout_width="match_parent" 8 android:layout_height="wrap_content" 9 android:id="@+id/button5" 10 android:onClick="login"/> 11 </LinearLayout>
Layout(login_layout登陸窗口)界面:
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:orientation="vertical" android:layout_width="match_parent" 4 android:layout_height="match_parent"> 5 <EditText 6 android:layout_width="match_parent" 7 android:layout_height="wrap_content" 8 android:inputType="text" 9 android:hint="請輸入用戶名" 10 android:id="@+id/et_username"/> 11 <EditText 12 android:layout_width="match_parent" 13 android:layout_height="wrap_content" 14 android:inputType="textPassword" 15 android:hint="請輸入密碼" 16 android:id="@+id/et_password"/> 17 </LinearLayout>
java功能實現代碼:
1 public class AlertDialogDemo extends AppCompatActivity {
2 private EditText et_username,et_password;
3 @Override
4 protected void onCreate(@Nullable Bundle savedInstanceState) {
5 super.onCreate(savedInstanceState);
6 setContentView(R.layout.alertdialog);
7 }
8 public void login(View v){
9 AlertDialog.Builder builder = new AlertDialog.Builder(this);
10 builder.setTitle("登錄");
11 //通過布局填充器獲login_layout
12 View view = getLayoutInflater().inflate(R.layout.login_layout,null);
13 //獲取兩個文本編輯框(密碼這裡不做登陸實現,僅演示)
14 final EditText et_username = (EditText) view.findViewById(R.id.et_username);
15 final EditText et_password = (EditText) view.findViewById(R.id.et_password);
16 builder.setView(view);//設置login_layout為對話提示框
17 builder.setCancelable(false);//設置為不可取消
18 //設置正面按鈕,並做事件處理
19 builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {
20 @Override
21 public void onClick(DialogInterface dialogInterface, int i) {
22 String name = et_username.getText().toString().trim();
23 String pass = et_password.getText().toString().trim();
24 Toast.makeText(AlertDialogDemo.this,name + "正在登錄....",Toast.LENGTH_SHORT).show();
25 }
26 });
27 //設置反面按鈕,並做事件處理
28 builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
29 @Override
30 public void onClick(DialogInterface dialogInterface, int i) {
31 Toast.makeText(AlertDialogDemo.this,"取消登錄",Toast.LENGTH_SHORT).show();
32 }
33 });
34 builder.show();//顯示Dialog對話框
35 }
36 }
關於數據抓取之xpath提取text為空問題的原因和解決方案
關於數據抓取之xpath提取text為空問題的原因和解決方案今天在抓取淘寶網網頁的時候,使用了:#店名 shopname = driver.find_element_by
Android反編譯和二次打包實戰
Android反編譯和二次打包實戰 作為Android開發者,工作中少不了要反編譯別人的apk,當然主要目的還是為了學習到更多,取彼之長,補己之短。今天就來總結一下A
Android Developer:內存分析器
Android Developer:內存分析器 Heap Viewer,Memory Monitor和Allocation Tracker是用來可視化你的app使用內存
翻翻git之---一個豐富的通知的工具庫 NotifyUtil
翻翻git之---一個豐富的通知的工具庫 NotifyUtil P2 正菜環節 今天上的是一個通知的工具庫,作者寫的比較全,使用起來頁比較方便,而且內容少,直接Co