自定义控件

引入控件:

  1、在activity_xml中添加<include layout="@layout/title">

  2、隐藏自带标题栏:在onCreate()中添加代码:ActionBar actionBar = getSupportActionBar();

                         if(actionBar != null){actionBar.hide();}

自定义控件:

1 public class TitleLayout extends LinearLayout{
2     public TitleLayout(Context context,AttributeSet attrs){
3         super(context,attrs);
4         LayoutInflater.from(context).inflate(R.layout.title,this);  //通过context构建LayoutInflater对象,调用inflate方法动态加载布局。
5     }
6 }

  添加自定义控件:

1 <LinearLayout......
2     <com.example.uicustimvies.TitleLayout  //指明控件的完整包名
3         android:layout_width="match_parent"
4         android:layout_height="warp_parent" />
5 </LinearLayout>

 

posted @ 2017-02-13 22:12  yl007  阅读(75)  评论(0编辑  收藏  举报