0

I am trying to make an Android app connect the phone to WiFi with a snackbar button that says, "Turn on WiFi." Currently, it just tells the user to connect to WiFi themselves, but I want the snackbar to connect the phone to WiFi when you click a button on the snackbar that says "Turn on WiFi."

1 Answers1

0

You can try this for your purpose it doesn't have button but tapping will show a dialog

     Snackbar snackbar = Snackbar
    .make(coordinatorLayout, "Wifi connection is off", Snackbar.LENGTH_LONG)
    .setAction("Turn On Wifi", new View.OnClickListener() {
        @Override
        public void onClick(View view) {
       //open dialog to turn on wifi
        }
    });
    snackbar.show();

to change the color of Wifi connection is off and Turn on Wifi use the following code snackbar.setActionTextColor(Color.RED);//turn on wifi View sbView = snackbar.getView(); TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text); textView.setTextColor(Color.YELLOW);//wifi connection is off

deejay
  • 572
  • 4
  • 18