在fragment中用代码声明控件

public class SubFragment1 extends Fragment {

 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {
  T.showShort(getActivity(), "SubFragment1==onCreateView");
  TextView tv = new TextView(getActivity());
  tv.setTextSize(25);
  tv.setBackgroundColor(Color.parseColor("#FFA07A"));
  tv.setText("新闻");
  tv.setGravity(Gravity.CENTER);
  return tv;
 }
}

转载于:https://my.oschina.net/u/1780920/blog/543050

你可能感兴趣的:(在fragment中用代码声明控件)