2016-02-06 26 views
0

我正在嘗試創建一個警報框,它彈出並顯示webview,用戶可以在其中登錄以檢查其電子郵件。警報框正在完美工作並顯示網頁。問題是當我想輸入mu電子郵件地址時,沒有鍵盤顯示輸入。當警報框彈出包含web視圖時,鍵盤不顯示

請幫助或者建議我其他方法。對於alertbox

代碼:

gmail.setOnClickListener(new OnClickListener() 
 
\t  { 
 
\t   @Override 
 
\t   public void onClick(View v) 
 
\t   { 
 
\t   \t 
 
\t   \t 
 
\t   \t AlertDialog.Builder alert = new AlertDialog.Builder(RegisterActivity.this); 
 
\t   \t alert.setTitle("Check Gmail"); 
 

 
\t   \t WebView wv = new WebView(RegisterActivity.this); 
 
\t   \t 
 
\t   \t wv.setOnTouchListener(new View.OnTouchListener() { 
 

 
\t  \t \t \t @Override 
 
\t  \t \t \t public boolean onTouch(View v, MotionEvent event) { 
 
\t      switch (event.getAction()) { 
 
\t      case MotionEvent.ACTION_DOWN: 
 
\t      case MotionEvent.ACTION_UP: 
 
\t       if (!v.hasFocus()) { 
 
\t        v.requestFocus(); 
 
\t       } 
 
\t       break; 
 
\t     } 
 
\t     return false; 
 
\t  \t \t \t } 
 
\t    }); 
 
\t   \t 
 
\t   \t wv.loadUrl("https://mail.google.com"); 
 
\t   \t wv.setWebViewClient(new WebViewClient() { 
 
\t   \t  @Override 
 
\t   \t  public boolean shouldOverrideUrlLoading(WebView view, String url) { 
 
\t   \t   view.loadUrl(url); 
 

 
\t   \t   return true; 
 
\t   \t  } 
 
\t   \t }); 
 

 
\t   \t alert.setView(wv); 
 
\t   \t alert.setNegativeButton("Close", new DialogInterface.OnClickListener() { 
 
\t   \t  @Override 
 
\t   \t  public void onClick(DialogInterface dialog, int id) { 
 
\t   \t   dialog.dismiss(); 
 
\t   \t  } 
 
\t   \t }); 
 
\t   \t alert.show(); 
 
\t   } 
 
\t  });

按照要求XML代碼:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    xmlns:tools="http://schemas.android.com/tools" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:orientation="vertical" 
 
    android:paddingBottom="@dimen/activity_vertical_margin" 
 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
 
    android:paddingRight="@dimen/activity_horizontal_margin" 
 
    android:paddingTop="@dimen/activity_vertical_margin" 
 
    tools:context="com.example.mohalogin.RegisterActivity" 
 
    android:background="@drawable/register" > 
 
    
 
    <TextView 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:text="Enter your name" /> 
 

 
    <EditText 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="wrap_content" 
 
     android:id="@+id/editTextName" /> 
 

 
    <TextView 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:text="Choose your username" /> 
 

 
    <EditText 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="wrap_content" 
 
     android:id="@+id/editTextUserName" /> 
 

 
    <TextView 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:text="Choose your password" /> 
 

 
    <EditText 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="wrap_content" 
 
     android:inputType="textPassword" 
 
     android:id="@+id/editTextPassword" /> 
 

 
    <TextView 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:text="Enter your email" /> 
 

 
    <EditText 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="wrap_content" 
 
     android:inputType="textEmailAddress" 
 
     android:id="@+id/editTextEmail" /> 
 

 
    <Button 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="wrap_content" 
 
     android:text="Register" 
 
     android:id="@+id/buttonRegister" /> 
 
    <TextView 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:textStyle="bold" 
 
     android:text="Already Registered" /> 
 

 
    <Button 
 
     android:layout_width="fill_parent" 
 
     android:layout_height="wrap_content" 
 
     android:text="Login" 
 
     android:id="@+id/buttonLogin" /> 
 
    
 
    <LinearLayout android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:orientation="horizontal" 
 
     android:padding="25dp"> 
 
     
 
     <Button 
 
     android:id="@+id/googleMail" 
 
     android:layout_width="50dp" 
 
     android:layout_height="50dp" 
 
     android:background="@drawable/gmail"/> 
 
     
 
     <Button 
 
     android:id="@+id/yahooMail" 
 
     android:layout_width="50dp" 
 
     android:layout_height="50dp" 
 
     android:background="@drawable/yahoo"/> 
 
     
 
     
 
    </LinearLayout> 
 

 
</LinearLayout>

+0

發佈您的xml代碼。 –

+0

@jaydroider先生這裏是我的xml代碼 – akshay270494

回答

0

看看這個question,這是相對的答案。

希望這會幫助你!

+0

感謝先生它的工作 – akshay270494

0

您需要爲Web視圖添加焦點。

只需更新如下。

wv.requestFocus(View.FOCUS_DOWN); 
wv.requestFocusFromTouch(); 
wv.setOnTouchListener(new View.OnTouchListener() { 
    @Override 
    public boolean onTouch(View v, MotionEvent event) { 
     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
      case MotionEvent.ACTION_UP: 
       if (!v.hasFocus()) { 
        v.requestFocus(); 
       } 
       break; 
     } 
     return false; 
    } 
}); 

希望這能解決您的問題。

+0

先生它不工作 – akshay270494

+0

檢查我編輯的答案。 –