How can ImageView link to web page?

后端 未结 3 991
我寻月下人不归
我寻月下人不归 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);
        }
    });
    
    0 讨论(0)
  • 2020-12-14 01:48

    That's truly possible, at onClick handler you need to start an activity with intent specifying the uri. See How to open default browser for example.

    0 讨论(0)
  • 2020-12-14 01:48

    another method we can even use is

        image.setOnClickListener(new OnClickListener() {
    
    @Override
    public void onClick(View arg0) {
    
    Intent redirect2=new Intent(getApplicationContext(),RedirectAct.class);
    startActivity(redirect2);
    
        }
    });
    
    0 讨论(0)
提交回复
热议问题