當前位置:首頁 » 安卓系統 » 輸入對話框android

輸入對話框android

發布時間: 2023-03-09 02:23:14

㈠ Android 點擊輸入框彈出鍵盤,布局隨鍵盤往上移動

一、效果圖:

二、Code:

/**

*  1、獲取main在窗體的可視區域

*  2、獲取main在窗體的不可視區域高度

*  3、判斷不可視區域高度,之前根據經驗值,在有些手機上有點不大准,現改成屏幕整體高度的1/3

*      1、大於屏幕整體高度的1/3:鍵盤顯示  獲取Scroll的窗體坐標

*                          算出main需要滾動的高度,使scroll顯示。

*      2、小於屏幕整體高度的1/3:鍵盤隱藏

*

* @param main 根布局 

* @param scroll 需要顯示的最下方View

*/

public static void addLayoutListener(final View main, final View scroll) {

    main.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

        @Override

        public void onGlobalLayout() {

            Rect rect = new Rect();

            main.getWindowVisibleDisplayFrame(rect);

            int screenHeight = main.getRootView().getHeight();

            int mainInvisibleHeight = main.getRootView().getHeight() - rect.bottom;

            if (mainInvisibleHeight > screenHeight / 4) {

                int[] location = new int[2];

                scroll.getLocationInWindow(location);

                int srollHeight = (location[1] + scroll.getHeight()) - rect.bottom;

                main.scrollTo(0, srollHeight);

            } else {

                main.scrollTo(0, 0);

}

}

});

}

三、調用方式:

在Activity的onCreate()中調用,

僅此記錄。

㈡ Edittext輸入框教程---Android APP安卓開發小白教程4

01  簡介

這篇文章主要是學習EditText輸入框的設置

android:hint輸入提升

android:textColorHint輸入提示的文字的顏色

android:drawableXxxx在輸入框的指定方位添加圖片

android:drawablePadding設置圖片與輸入內容的間距

android:paddingXxxx設置內容和邊框的間距

android:background背景色

02  操作

這是在輸入類型InputType裡面設置的

首先添加EditText

這個inputType的類型自己可以去摸索

裡面的phone就是這個效果

03  圖標以及密碼框的設置

先再添加一個EditText

圖標的設置,參考上一篇文章裡面在Drawable裡面添加的圖片選擇器,之後加上

android:drawableLeft="@drawable/ic_baseline_account_box_24"

drawableLeft這個是將圖標設置在輸入框的左邊,Drawablepadding可以調圖標與輸入內容的間距

04  如何獲取輸入框裡面的內容

要獲取用戶名的話就得再添加一個button

並且在裡面添加一個id

同時在要獲取 的那個EditText裡面添加一個id 

在點擊事件裡面添加一個讀取editText內容方法

btn.setOnClickListener(newView.OnClickListener(){            @OverridepublicvoidonClick(View v) {                String text1 = et1.getText().toString();Log.e("chuangzhangkeji","YONGHUMING:"+text1);                String text2 = et2.getText().toString();Log.e("chuangzhangkeji","MIMA:"+text2);            }

 Log.e()這個是調用列印的方法把獲取到的的信息列印出來

et1.getText().toString();是獲取輸入的數據並將其轉化為字元串

05  測試

     點擊登入之後就會在logcat裡面出現

船長科技

電子人,極客開發者,電子信息工程在讀,介紹科技類,科幻類,以及分享一些互聯網學習經驗公眾號  

歡迎關注「船長科技」

船長和你一起走進科技

探索生活中的科技

保持一顆好奇心

㈢ android如何實現一個彈出輸入對話框呢

1、在「常規」選項卡中輸入目標計算機的IP地址,以及登陸計算機的用戶名和密碼
2、如果目標計算機屬於某一個域,需要輸入該域的域名
3、要在下次連接十幾株密碼,可以選中「保存密碼」復選框
4、單擊「另存為」,可以將當前的連接設置保存到一個文件中。
5、單擊「打開」按鈕,可從一個文件中讀取連接設置

㈣ android 彈出輸入框並得到輸入框的結果

不用找了,這才是正解。你的需求其實是,需要一個阻塞式對話框,安卓本身所有彈窗都是非阻塞的。

import android.app.Activity;

import android.app.AlertDialog;

import android.content.DialogInterface;

import android.os.Handler;

import android.os.Looper;

import android.os.Message;

import android.widget.EditText;

/**

* 動態獲取用戶輸入後在繼續後面的流程

* 這是一個模態阻塞對話框(阻塞主線程,結果不用回調來處理)

*/

public class BlockingInputDialog {

String mInputString = "";

Activity mContext;

String mTitle;

EditText mEditText;

Handler mHandler;

public BlockingInputDialog(Activity context, String title){

mContext = context;

mTitle = title;

}

public String showDialog(){

mHandler = new Handler(){

@Override

public void handleMessage(Message msg) {

//super.handleMessage(msg);

throw new RuntimeException();

}

};

AlertDialog.Builder builder = new AlertDialog.Builder(mContext);

builder.setTitle(mTitle);

builder.setCancelable(false);

mEditText = new EditText(mContext);

builder.setView(mEditText);

builder.setPositiveButton("確定", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialogInterface, int i) {

mInputString = mEditText.getText().toString();

Message message = mHandler.obtainMessage();

mHandler.sendMessage(message);

}

});

builder.setNegativeButton("取消", null);

builder.create().show();

try {

Looper.getMainLooper().loop();

}

catch(RuntimeException e2)

{

}

return mInputString;

}

}

㈤ android 怎樣彈出選擇輸入法的對話框 如下圖

1.讓EditText失去焦點,使用EditText的clearFocus方法2.強制隱藏Android輸入法窗口,在IME類中我們通過InputMethodManagerimm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);實例化輸入法控制對象,通過hideSoftInputFromWindow來控制,其中第一個參數綁定的為需要隱藏輸入法的EditText對象,比如imm.hideSoftInputFromWindow(etAndroid123.getWindowToken(),0);

㈥ android:自定義可輸入對話框,EditText已經獲得焦點,為什麼就是不彈出輸入法呢

因為你彈出的對話框跟MainActivity(假設你是在MainActivity上他彈出的)不在同一個Activity上,所以就顯示不出來了,就算你能看到軟鍵盤你也無法輸入。

㈦ android 對話框 如何 獲取輸入框值

String name=username.getText().toString();
String pass=password.getText().toString();
把它們寫到這個監聽器的外面來試試。

㈧ android如何實現一個彈出輸入對話框呢

java">AlertDialog.Builderbuilder=newAlertDialog.Builder(context);
builder.setTitle("提示");
builder.setMessage("恭喜你,注冊成功!");
builder.setPositiveButton("去登錄",newDialogInterface.OnClickListener(){ //增加一個成功按鈕,並增加點擊事件
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){
//點擊去登錄的操作
}
});
builder.setNegativeButton("繼續注冊",newDialogInterface.OnClickListener(){ //增加一個中間的按鈕,並增加點擊事件
@Override
publicvoidonClick(DialogInterfacedialog,intwhich){

//點擊繼續注冊的操作
}
});
builder.setCancelable(false); //彈出框不可以按返回取消
AlertDialogdialog=builder.create(); //創建對話框
dialog.setCanceledOnTouchOutside(false); //設置對話框失去焦點不會消息
dialog.show(); //彈出

㈨ android怎樣實現彈出多個輸入對話框

1.布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:background="#ffffffff" android:orientation="horizontal"
android:id="@+id/dialog">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/tvname" android:text="姓名:" />
<EditText android:layout_height="wrap_content"
android:layout_width="wrap_content" android:id="@+id/etname" android:minWidth="100dip"/>
</LinearLayout>
2.調用代碼
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.dialog,
(ViewGroup) findViewById(R.id.dialog));
new AlertDialog.Builder(this).setTitle("自定義布局").setView(layout)
.setPositiveButton("確定", null)
.setNegativeButton("取消", null).show();

簡單來說就是自定義dialog就好了
在裡面創建兩個對話框,也就是edittext
你試試看我這個代碼。

熱點內容
存儲伺服器分類 發布:2025-05-14 08:39:01 瀏覽:645
xz文件解壓軟體 發布:2025-05-14 08:28:43 瀏覽:969
lua腳本學習 發布:2025-05-14 08:20:55 瀏覽:713
python文件刪除一行 發布:2025-05-14 08:06:58 瀏覽:721
如何下載奧特曼高級化3安卓版 發布:2025-05-14 07:47:31 瀏覽:346
qml文件修改後編譯未生效 發布:2025-05-14 07:31:00 瀏覽:331
內到內演算法 發布:2025-05-14 07:29:11 瀏覽:34
文件夾名字不顯示 發布:2025-05-14 07:27:47 瀏覽:775
oracle的資料庫驅動jar 發布:2025-05-14 07:23:20 瀏覽:556
我的世界電腦版伺服器手機版能進嗎 發布:2025-05-14 07:22:01 瀏覽:680