在我的一个活动中,有一个按钮,按下此按钮会打开一个对话框片段,在此对话框片段中会出现一个Web视图。我使用这个Web视图来获取在线商店的用户信息,但是当在Web视图上加载表单时,我想输入信息软键盘没有出现。 在另一个活动中显示Web视图是可以的,一切正常,我可以输入数据。
调用对话框片段的主要活动:
public class MainActivity extends AppCompatActivity implements InformationDialog44.InformationDialogInfo {
Activity activity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
activity=this;
Button button=(Button)findViewById(R.id.showButton);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InformationDialog44 dialog=new InformationDialog44();
dialog.show(getSupportFragmentManager(),"parvaz-tag");
}
});
}
}
这是主要布局(content_main.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="ir.parvaz.uitests.MainActivity"
tools:showIn="@layout/activity_main">
<Button
android:id="@+id/showButton"
android:text="Show Dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
这是片段布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_margin="10dp"
android:padding="10dp"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Hello World!"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<WebView
android:id="@+id/myWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"></WebView>
</LinearLayout>
和片段代码:
public class InformationDialog44 extends DialogFragment {
InformationDialog44 myself;
InformationDialogInfo listener;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
super.onCreateDialog(savedInstanceState);
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view=inflater.inflate(R.layout.dialog2,null);
builder.setView(view);
WebView myWebView=(WebView)view.findViewById(R.id.myWebView);
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
myWebView.getSettings().setLoadWithOverviewMode(true);
myWebView.getSettings().setUseWideViewPort(true);
myWebView.setWebViewClient(new WebViewClient()
{
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, final String url) {
Log.i("parvaz-uitests","URL is: "+url);
}
}
);
myWebView.setBackgroundColor(Color.BLUE);
myself=this;
myWebView.loadUrl("http://www.google.com");
return builder.create();
}
@Override
public void onAttach(Activity activity)
{
super.onAttach(activity);
try
{
listener=(InformationDialogInfo)activity;
}
catch(ClassCastException e)
{
Log.e("parvaz-error","Implement InformationDialogInfo. ");
dismiss();
}
}
public interface InformationDialogInfo
{
void onOKClick(InformationDialog44 informationDialog);
void onCancelClick(InformationDialog44 informationDialog);
}
}
是否有任何限制(可能出于安全原因)不允许在对话框片段中的Web视图上使用键盘?
答案 0 :(得分:0)
似乎没有人有一个正确的答案。我无法通过这种方式解决问题,但最简单的方法是将您的活动显示为已回答here的对话框。
但在我的情况下,我不得不用以下样式替换样式名称:android:theme =“@ android:style / Theme.Dialog”