X
X
xaiponews2020-09-12 19:12:43
Android
xaiponews, 2020-09-12 19:12:43

How to add a button to open the site?

There is a WebViwe object, by default it displays the google.com page. How to add a button so that when you click on it, in the same WebViwe object, the yandex.ru page opens?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg, 2020-09-12
@xaiponews

webView.loadUrl(" https://ya.ru ")
Instead of a button, I would add a menu item to "..." (top-right corner)
https://startandroid.ru/ru/uroki/vse-uroki-spiskom ...

X
xaiponews, 2020-09-12
@xaiponews

public class MainActivity extends AppCompatActivity {
    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Button butacc = findViewById(R.id.butacc);
        butacc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                webView.loadUrl("http://ya.ru");
            }
        });

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question