设为首页 加入收藏

TOP

Android定制属于你自己的导航栏
2014-11-24 07:34:54 来源: 作者: 【 】 浏览:2
Tags:Android 定制 属于 自己 导航


其实实现这样的效果有多种方式,今天我要给大家要介绍的就是如何的去定制自己的控件,也就是自定义控件,自定义控件分为多种,有组合控件,有重写在原来已有的控件上做基础的修改,也有自己重写写一个类继承于View对象,这方面的知识在实际开发当中也会常碰到,当然像我们这种菜鸟在这方面也是最欠缺的一个知识点,我希望通过我的一些讲解或者分享能帮助到大家吧。今天我给大家讲的就是组合控件的自定义,在后续的博文中我也希望自己能发现更多的这种自定义控件的能力然后再与大家分享,同样如果大家有好的分享的东西也可以与我一起分享。就拿今天的一个效果如何去实现自定义控件,我会采用两种方式去实现,一种就是纯粹的代码方式实现,一种就是用LayoyutInfalter去实现。


先说XML方式的实现方式:


先定义一个XML布局文件:


< xml version="1.0" encoding="utf-8" >
android:layout_width="fill_parent"
android:layout_height="45dip"
android:background="@drawable/navigation_bg"
android:gravity="center_vertical"
android:orientation="horizontal" >


android:id="@+id/btn_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10.0dip"
android:background="@drawable/backbg"
android:text="返回"
android:textColor="@android:color/white" />


android:id="@+id/tv_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:text="标题"
android:textColor="@android:color/white" />


android:id="@+id/btn_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10.0dip"
android:background="@drawable/buttonbg"
android:text="新增"
android:textColor="@android:color/white" />



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android实现垂直型的SeekBar 下一篇Android自定义属性,attr format..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Redis 分布式锁全解 (2025-12-25 17:19:51)
·SpringBoot 整合 Red (2025-12-25 17:19:48)
·MongoDB 索引 - 菜鸟 (2025-12-25 17:19:45)
·What Is Linux (2025-12-25 16:57:17)
·Linux小白必备:超全 (2025-12-25 16:57:14)