Skip to content

Instantly share code, notes, and snippets.

//inside a fragment. If in an Activity you could use findViewById(Window.ID_ANDROID_CONTENT);
getView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
@Override
public void onGlobalLayout()
{
//do something like measure a view etc
View content = getWindow().findViewById(Window.ID_ANDROID_CONTENT);
Log.d("DISPLAY", content.getWidth() + " x " + content.getHeight());
@z8888q
z8888q / gist:056ff15d7bfa5fff57985bf4f08e907b
Last active May 31, 2017 09:14
Implement dynamic delete or add tab(TAB_C in this test code). Initial Conditions: use Android Studio 2.3.2 create a new Project with a Tabbed Activity, and the Navigation style is Action Bar Tabs(with ViewPager).
package com.zq.testviewpager;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.support.v4.app.Fragment;