Search code examples
androidandroid-toolbar

how to disable toolbar in webview


I'm trying to hide toolbar in webview.

This is my source code:

@RequiresApi(api = Build.VERSION_CODES.KITKAT)
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    CookieSyncManager.createInstance(getApplicationContext());
    CookieSyncManager.getInstance().startSync();
    setContentView(R.layout.activity_affiliate_view);

    Toolbar toolbar = findViewById(R.id.toolbar);
    toolbarTextView = findViewById(R.id.toolbarTextView);

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(false);
    getSupportActionBar().setDisplayShowHomeEnabled(false);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    toolbarTextView.setText("Product Details");


    progressBar = findViewById(R.id.progressbar);

    progressBar.setVisibility(View.VISIBLE); // To show the ProgressBar

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

this is image:

1


Solution

  • You can create a new style without toolbar in themes.xml file and apply it to a specific activity from manifest

    themes.xml

    <style name="CustomStyle" parent="Theme.MaterialComponents.Light.NoActionBar">
        <item name="colorPrimary">@color/purple_500</item>
        <item name="colorPrimaryVariant">@color/purple_700</item>
    </style>
    

    AndroidManifest.xml

    <activity
      android:name=".AffiliateViewActivity"
      android:exported="false"
      android:theme="@style/CustomStyle"/>