开发者

How can ImageView link to web page?

开发者 https://www.devze.com 2023-01-12 06:54 出处:网络
is it poss开发者_运维知识库ible 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:

is it poss开发者_运维知识库ible 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);
    }
});


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.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号