Add back button toolbar android studio

If you are using android studio and you want to add back button toolbar, then follow the below steps.

Paste this code in your java file


 

Add back button android studio

Java



      
        package in.app.androidpro.makemoneyonline;

        import androidx.appcompat.app.ActionBar;
        import androidx.appcompat.app.AppCompatActivity;
        
        
        import android.os.Bundle;
        import android.view.Menu;
        import android.view.MenuItem;
        import android.webkit.WebView;
        
        public class Card1 extends AppCompatActivity {
        
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.activity_card1);
        
        
                ActionBar actionBar = getSupportActionBar();
                if (actionBar != null) {
                    actionBar.setDisplayHomeAsUpEnabled(true);
                }
        
                    WebView webView;
                    webView = findViewById(R.id.webview);
                    webView.loadUrl("file:///android_asset/Start A YouTube Channel.html");
                }
        
            public boolean onOptionsItemSelected(MenuItem item){
                switch (item.getItemId()) {
                    case android.R.id.home:
                        finish();
                        return true;
                }
                return super.onOptionsItemSelected(item);
            }
        
            public boolean onCreateOptionsMenu(Menu menu) {
                return true;
        
            }
        }
        
        
        
       
        
    

Post a Comment

0 Comments