如何ImageView的链接到网页?链接、网页、ImageView

2023-09-13 00:40:25 作者:余生陪你去浪

是否有可能作出的ImageView链接到一个网页,这样当用户点击图片,它需要他们的网页?

is it possible to make an imageview link to a web page such that when user taps on the image, it takes them to a web page?

推荐答案

只需添加一个点击监听器的影像打开一个网址:

Just add a click listener to the image to open an URL:

ImageView img = (ImageView)findViewById(R.id.foo_bar);
img.setOnClickListener(new View.OnClickListener(){
    public void onClick(View v){
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_VIEW);
        intent.addCategory(Intent.CATEGORY_BROWSABLE);
        intent.setData(Uri.parse("http://casidiablo.net"));
        startActivity(intent);
    }
});