How to open a website when a Button is clicked in Android application?

前端 未结 10 2084
囚心锁ツ
囚心锁ツ 2020-12-01 00:23

I am designing an app, with several button for users to click on. Once button is clicked, user is directed to appropriate website. How do I accomplish this?

10条回答
  •  一个人的身影
    2020-12-01 01:02

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

提交回复
热议问题