Created
December 28, 2015 02:32
-
-
Save ccjeng/b6d9d2da054722703c49 to your computer and use it in GitHub Desktop.
Android TabLayout TabFragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TabFragment extends Fragment { | |
private static final String ARG_POSITION = "position"; | |
private int position; | |
public static TabFragment newInstance(int position) { | |
TabFragment f = new TabFragment(); | |
Bundle b = new Bundle(); | |
b.putInt(ARG_POSITION, position); | |
f.setArguments(b); | |
return f; | |
} | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
position = getArguments().getInt(ARG_POSITION); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); | |
FrameLayout fl = new FrameLayout(getActivity()); | |
fl.setLayoutParams(params); | |
TextView v = new TextView(getActivity()); | |
v.setLayoutParams(params); | |
v.setLayoutParams(params); | |
v.setGravity(Gravity.CENTER); | |
v.setBackgroundResource(R.color.windowBackground); | |
v.setText("Tab " + (position + 1)); | |
fl.addView(v); | |
return fl; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment