How can ImageView link to web page?

后端 未结 3 993
我寻月下人不归
我寻月下人不归 2020-12-14 01:24

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?

3条回答
  •  一个人的身影
    2020-12-14 01:35

    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);
        }
    });
    

提交回复
热议问题