Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android浏览器中的地址栏_Java_Android_Address Bar - Fatal编程技术网

Java android浏览器中的地址栏

Java android浏览器中的地址栏,java,android,address-bar,Java,Android,Address Bar,在我的应用程序中有一个webView,默认网站为谷歌。我在任何网页上的一些应用程序中都可以看到顶部有一个地址栏,所以用户可以随时输入新的网站地址。我们怎么能做到呢 以下是你需要做的最基本的事情。当然,你必须根据你的需要进行增强 activity_webview.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/

在我的应用程序中有一个
webView
,默认网站为谷歌。我在任何网页上的一些应用程序中都可以看到顶部有一个地址栏,所以用户可以随时输入新的网站地址。我们怎么能做到呢

以下是你需要做的最基本的事情。当然,你必须根据你的需要进行增强

activity_webview.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:orientation="vertical"
     tools:context="com.carworkz.dearo.WebviewActivity">

<EditText
    android:id="@+id/et_web_address"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:inputType="textWebEditText"
    android:imeOptions="actionGo"
    android:hint="Enter Url" />

<WebView
    android:id="@+id/webview"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</LinearLayout>

欢迎来到stack overflow,请阅读并更新您的问题以使其更合适,您尝试过什么或读过什么?可能重复:可能重复
public class WebviewActivity extends AppCompatActivity {

private EditText webAddressView;
private WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_webview);
    webAddressView = (EditText) findViewById(R.id.et_web_address);
    webView = (WebView) findViewById(R.id.webview);

    webAddressView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_GO) {
                String url = webAddressView.getText().toString();
                if (!url.isEmpty())
                    webView.loadUrl(url);
                return true;
            }
            return false;
        }
    });
}
}