Tabs with different sizes (Viewpager)

Asked

Viewed 38 times

-1

I need to create an APP with multiple tabs, same as Tagram and Whatsapp. And that when you pass to a specific Tab, it stays in fullScreem, or unless the Actionbar disappears, and when you pass to other Tabs everything goes back to normal.

PS: It is exactly the same as Whatsapp that when dragging to the camera Tab, the screen is in fullScreem.

Activity Main

public class MainActivity extends AppCompatActivity {

private final int PERMISSAO_REQUEST = 2;

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

    //deixa em FullScreem
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

    //IMPORTANTE: aqui verifica as permiçoes
    permicoes();

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    pager.setAdapter(new MyPagerAdapter(getSupportFragmentManager()));
}

private void permicoes() {
    //USUARIA DAR A PERMISSAO
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.CAMERA)
            != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.CAMERA)) {
        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.CAMERA},
                    PERMISSAO_REQUEST);
        }
    }

    //USUARIA DAR A PERMISSAO
    if (ContextCompat.checkSelfPermission(this,
            Manifest.permission.READ_EXTERNAL_STORAGE)
            != PackageManager.PERMISSION_GRANTED) {
        if (ActivityCompat.shouldShowRequestPermissionRationale(this,
                Manifest.permission.READ_EXTERNAL_STORAGE)) {
        } else {
            ActivityCompat.requestPermissions(this,
                    new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
                    PERMISSAO_REQUEST);
        }
    }
}

private class MyPagerAdapter extends FragmentPagerAdapter {

    public MyPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int pos) {
        switch(pos) {
            //IMPORTANTE: Ao adicionar ou retirar case's, ATUALIZE o getCount() abaixo
            case 0: return CameraFragment.newInstance("CameraFragment, Instance 1");
            default: return TelaPrincipalFragment.newInstance("TelaPrincipalFragment, Default");
        }
    }

    @Override
    public int getCount() {
        //IMPORTANTE representa o numero de telas (la no switch)
        return 2;
    }
}

@Override
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    if (requestCode == PERMISSAO_REQUEST) {
        if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
            // A permissão foi concedida. Pode continuar
        } else {
            // A permissão foi negada. Precisa ver o que deve ser desabilitado
        }
        return;
    }
}

}

Fragment 1 (only one excerpt)

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

    surfaceView = v.findViewById(R.id.surfaceView);
    surfaceHolder = surfaceView.getHolder();

    //Instalamos uma surfaceHolder.Callback então nós notificamos quando o underlying surface é criado e destroido.
    surfaceHolder.addCallback(this);
    //APARENTEMENTE essa linha nao foi necessaria
    //surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);

    return v;
}

Fragment 2

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

    lvListaMaterias = (ListView) v.findViewById(R.id.lvListaMaterias);

    return v;
}

Basically that’s it, I want that during Fragment 1 the screen is fullscreem, and when it goes to Fragment 2 the screen goes back to normal, with action bar, etc.

  • Hello, Everson! What have you done so far? Post at least your codes that make the default tabs (tabs), from this we can help you better.

  • @Luídne put the codes. vlw

1 answer

1


I found the answer:

    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
actionBar = getSupportActionBar(); 
actionBar.hide();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.