android – Trying To Fix The Code That Cannot Make the WebView Fullscreen

package com.example.digitialin;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;

import androidx.fragment.app.Fragment;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link HistoryFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class HistoryFragment extends Fragment {
    private View mCustomView;
    private WebChromeClient.CustomViewCallback mCustomViewCallback;
    protected FrameLayout mFullscreenContainer;
    private int mOriginalOrientation;
    private int mOriginalSystemUiVisibility;



    private boolean resetHistory = true;
    @SuppressLint("SetJavaScriptEnabled")



    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    public HistoryFragment() {

        // Required empty public constructor
    }


    /**
     * Use this factory method to create a new instance of
     * this fragment using the provided parameters.
     *
     * @param param1 Parameter 1.
     * @param param2 Parameter 2.
     * @return A new instance of fragment HistoryFragment.
     */
    // TODO: Rename and change types and number of parameters
    public static HistoryFragment newInstance(String param1, String param2) {
        HistoryFragment fragment = new HistoryFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
        
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_history, container, false);

        String url = "https://75.119.159.228/";
        WebView view = (WebView) rootView.findViewById(R.id.webView2);

        view.setWebViewClient(new WebViewClient());
        view.getSettings().setJavaScriptEnabled(true);
        view.getSettings().setUserAgentString("Desktop");
        view.getSettings().setAllowFileAccess(true);
        view.getSettings().setAppCacheEnabled(true);
        view.getSettings().setBuiltInZoomControls(true);
        view.getSettings().setSaveFormData(true);
        view.getSettings().setPluginState(WebSettings.PluginState.ON);
        view.loadUrl(url);


        return rootView ;
        // Inflate the layout for this fragment
    }



}

This code i tried implemented to just open and watch video fullscreen by webview but it always fails

i tried managing and searched accross the web didnt found the solution yet , hopefully someone can help me im really new to java

im trying to play the video by youtube or html player any way 14

4 How to make the webview of an android application full screen. I have added the webview on a layout xml file but it doesn’t stretches out till the edges of the layout, there is some type of margin along all the side of the webview. I am also adding an image to give you guys a hint on what actually it is looking like.

This Is The Dashboard

package com.example.digitialin;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.firestore.FirebaseFirestore;
import com.google.firebase.storage.StorageReference;

public class DashboardActivity extends AppCompatActivity {
    private static final int GALLERY_INTENT_CODE = 1023 ;
    Button m_lout_btn_1;
    private FirebaseUser firebaseUser;
    FirebaseAuth mAuth;
    FirebaseUser user;
    FirebaseFirestore fStore;
    BottomNavigationView bottomNavigation;
    ImageView profileImage;
    StorageReference storageReference;
    FirebaseAuth.AuthStateListener mAuthListener;
    private int oldOptions;
    private WebView webView;
    private FrameLayout customViewContainer;
    private WebChromeClient.CustomViewCallback customViewCallback;
    private View mCustomView;



    @SuppressLint("SetTextI18n")

    @Override
    protected void onStart() {
        super.onStart();
        mAuth.addAuthStateListener(mAuthListener);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
        setContentView(R.layout.activity_dashboard);
        firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
        bottomNavigation = findViewById(R.id.bottom_navigation);
        m_lout_btn_1 = (Button) findViewById(R.id.d_lout_btn_1);
        mAuth = FirebaseAuth.getInstance();
        mAuthListener = new FirebaseAuth.AuthStateListener() {
            @Override
            public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
                if(firebaseAuth.getCurrentUser() == null) {
                    startActivity(new Intent(DashboardActivity.this, MainActivity.class));
                }
            }
        };

        bottomNavigation.setBackground(null);
        bottomNavigation.getMenu().getItem(2).setEnabled(false);
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,new HomeFragment()).commit();
        bottomNavigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment temp = null;
                switch (item.getItemId())
                {
                    case R.id.nav_home : temp = new HomeFragment();
                        break;
                    case R.id.nav_history : temp = new HistoryFragment();
                        break;
                    case R.id.nav_chats : temp = new ChatsFragment();
                        break;
                    case R.id.nav_account : temp = new AccountFragment();
                }
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container,temp).commit();
                return true;
            }

        });




    }
    @Override
    public void onConfigurationChanged(Configuration newConfig)
    {
        super.onConfigurationChanged(newConfig);

        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
        {
            oldOptions = getWindow().getDecorView().getSystemUiVisibility();
            int newOptions = oldOptions;
            newOptions &= ~View.SYSTEM_UI_FLAG_LOW_PROFILE;
            newOptions |= View.SYSTEM_UI_FLAG_FULLSCREEN;
            newOptions |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
            newOptions |= View.SYSTEM_UI_FLAG_IMMERSIVE;
            newOptions &= ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
            getWindow().getDecorView().setSystemUiVisibility(newOptions);
            getActionBar().hide();
        }
        else
        {
            getWindow().getDecorView().setSystemUiVisibility(oldOptions);
            getActionBar().show();
        }
    }
}

Leave a Comment