自定义控件
引入控件:
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>
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步