Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.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 studio中将URL添加到图像?_Java_Android_Xml - Fatal编程技术网

Java 如何在android studio中将URL添加到图像?

Java 如何在android studio中将URL添加到图像?,java,android,xml,Java,Android,Xml,我希望在我的应用程序中,当有人单击图像时,它会以默认浏览器打开 我到处都找过,但没有办法帮我 <RelativeLayout 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" andro

我希望在我的应用程序中,当有人单击图像时,它会以默认浏览器打开

我到处都找过,但没有办法帮我

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".Home_Activity"
android:background="#FF0000">

<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/AppTitleimage1"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:src="@mipmap/fra"
    android:contentDescription="@string/AppTitleImageS"
    android:autoLink="web"
    android:clickable="true" />
但当我将其粘贴到java类中时,它会说:

“无法解析方法'findViewById'(?) 和 “无法解析符号“weblink” 和 “无法解析方法startActivity(android.content.intent)


我的问题不同,答案不起作用

最快的设置方法可能是添加

android:onClick="goToUrl"
添加到imageview,并将此函数添加到类中

 private void goToUrl (View view) {
        String url = "http://www.google.com"
        Uri uriUrl = Uri.parse(url);
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
        startActivity(launchBrowser);
 }

最快的设置方法可能是添加

android:onClick="goToUrl"
添加到imageview,并将此函数添加到类中

 private void goToUrl (View view) {
        String url = "http://www.google.com"
        Uri uriUrl = Uri.parse(url);
        Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
        startActivity(launchBrowser);
 }

您可以为
imageView
实现
onClick
,并可以从那里打开url:

例如:

ImageView imageView = (ImageView) findViewById(R.id.AppTitleimage1);
imageView.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View v)
            {
                Uri uri = Uri.parse("http://www.google.com"); 
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent); 
            }
         });

您可以为
imageView
实现
onClick
,并可以从那里打开url:

例如:

ImageView imageView = (ImageView) findViewById(R.id.AppTitleimage1);
imageView.setOnClickListener(new View.OnClickListener() {  
        public void onClick(View v)
            {
                Uri uri = Uri.parse("http://www.google.com"); 
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent); 
            }
         });

duplicated:duplicated:我必须将其粘贴到哪里?在您设置内容后的活动的onCreate中。我必须将其粘贴到哪里?在您设置内容后的活动的onCreate中。嗨,ashley,我必须将其粘贴到哪里?顶部应该进入您的图像xml视图中。您输入要使用的类的另一部分g onclick效果。可能是一个活动类或片段。嗨,ashley,我必须将其粘贴到哪里?顶部部分应该进入图像xml视图。另一部分是您进入将要使用onclick效果的类的部分。可能是一个活动类或片段。代码的简要描述,例如关键函数它的工作原理将有助于用户从代码中学习并使其适应自己的项目。对代码的简要描述,如关键功能和工作原理,将有助于用户从代码中学习并使其适应自己的项目。