自定义了一个标题栏类TitleLayout
来源:互联网 发布:数据管理软件开发 编辑:程序博客网 时间:2024/06/06 19:22
直接上代码,大家在以后的开发中根据实际需求可以做一些修改。
/** * Created by 杨阳洋 on 2016/12/9. */public class TitleLayout extends LinearLayout { private Button mBtn_back; private Button mBtn_next; public TitleLayout(Context context) { this(context,null); } public TitleLayout(Context context, AttributeSet attrs) { this(context, attrs,0); } public TitleLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); //参数2:是给加载好的布局再添加一个父布局 LayoutInflater.from(context).inflate(R.layout.title,this); initData(); initListener(); } private void initData() { mBtn_back = (Button) findViewById(btn_back); mBtn_next = (Button) findViewById(btn_next); } private void initListener() { mBtn_back.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ((Activity)getContext()).finish(); } }); mBtn_next.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getContext(), R.string.app_name , Toast.LENGTH_SHORT).show(); } }); }}
布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/title_bg" android:orientation="horizontal"> <Button android:id="@+id/btn_back" android:layout_width="20dp" android:layout_gravity="center" android:layout_height="20dp" android:layout_marginLeft="5dp" android:background="@drawable/ic_back" android:gravity="center"/> <TextView android:id="@+id/title_text" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:gravity="center" android:layout_gravity="center_vertical" android:text="@string/title" android:textSize="20sp"/> <Button android:id="@+id/btn_next" android:layout_width="20dp" android:layout_height="20dp" android:layout_marginRight="5dp" android:layout_gravity="center" android:background="@drawable/ic_back01" android:gravity="center"/></LinearLayout>
0 0
- 自定义了一个标题栏类TitleLayout
- Android封装一个自定义标题栏
- 【Android】自定义标题栏 (解决了标题栏两侧空隙问题)
- 如何自定义一个自己的标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义标题栏
- 自定义 标题栏
- Paper Note - Learning to Hash with Binary Deep Neural Network
- js-return返回多个值,通过对象的属性访问
- Tutorial: 344. Reverse String
- 浅识 VB.net
- 数组-选择排序-记录下标
- 自定义了一个标题栏类TitleLayout
- 基于vue.js开发的demo—天气APP
- SourceInsight使用技巧
- JAVA “初始化与清理”
- M. 今年暑假不AC
- JSP及JSP的9大隐含变量
- 送给前线码农的话 - 大牛们的经典语录
- [hackerrank Random]
- 02、C语言-函数