其实大家看到都ActionBar说白了,就是自定义的一个Linearlayout或者RelatedLayout;今天就练练LinearLayout

自定义。

LinearLayout自定义方法有多种:

1、自定义xml布局,然后加载布局,自定义一个View继承LinearLayout

2、在自定义控件中声明它的所有子元素,然后在Layout文件中像使用LinearLayout一样去进行布局,

第二种比较烦 ,它需要在Layout文件中定义好子元素之后,要在代码 onFinishInflate() 进行匹配子元素

我就说说加载布局文件的方法吧。

首先:定义好layout文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal" ><ImageViewandroid:id="@+id/imageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:paddingBottom="5dip"android:paddingLeft="40dip"android:paddingTop="5dip"android:src="@drawable/right_icon" /><TextViewandroid:id="@+id/textView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:layout_marginLeft="8dip"android:text="主题"android:textColor="#000000" /><LinearLayout android:layout_width="100dp"android:layout_height="fill_parent"android:orientation="horizontal" ><ImageViewandroid:id="@+id/imageView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:paddingBottom="5dip"android:paddingLeft="12dip"android:paddingTop="5dip"android:src="@drawable/home_icon" /><ImageViewandroid:id="@+id/imageView3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:paddingBottom="5dip"android:paddingLeft="12dip"android:paddingTop="5dip"android:src="@drawable/add_icon" /></LinearLayout></LinearLayout>

接下来自定义一个MyLinearLayout继承 LinearLayout,并且加载刚刚写好的layout文件。

public class MyLinearLayout extends LinearLayout {private ImageView imageView,iv_home,iv_add;private TextView  textView;public MyLinearLayout (Context context) {super(context);// TODO Auto-generated constructor stub}public MyLinearLayout (Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stubLayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);inflater.inflate(R.layout.actionbar, this);imageView=(ImageView) findViewById(R.id.imageView1);iv_home=(ImageView) findViewById(R.id.imageView2);iv_add=(ImageView) findViewById(R.id.imageView3);textView=(TextView)findViewById(R.id.textView1);}/** * 设置图片资源 */  public void setImageResource(int resId) {  imageView.setImageResource(resId);  }  /** * 设置显示的文字 */  public void setTextViewText(String text) {  textView.setText(text);  }  }

再者:需要的时候使用定义好的MyLinearLayout控件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="horizontal" ><cn.com.demo.view.MyLinearLayoutandroid:id="@+id/ll_actionbar"android:layout_height="fill_parent<span style="font-family: Tahoma, 'Microsoft Yahei', Simsun;">"  </span>
android:layout_width="wrap_content"android:background="@drawable/bg"  />
</LinearLayout>

【android自定义控件】LinearLayout定义ActionBar样式相关推荐

  1. 【Android 应用开发】 ActionBar 样式详解 -- 样式 主题 简介 Actionbar 的 icon logo 标题 菜单样式修改

    作者 : 万境绝尘 (octopus_truth@163.com) 转载请著名出处 : http://blog.csdn.net/shulianghan/article/details/3926916 ...

  2. android 自定义控件linearlayout,自定义控件(瀑布流,LinearLayout)

    通过转发触摸事件来单独对某个view进行控制处理. xmlns:tools="http://schemas.android.com/tools" android:layout_wi ...

  3. android 自定义控件 焦点,Android 自定义Button按钮显示样式(正常、按下、获取焦点)...

    现在的用户对APP的外观看得很重要,如果APP内所有元件都用Android默认样式写,估计下面评论里就有一堆在骂UI丑的.今天学习自定义Button按钮样式.Button样式修改的是Button的背景 ...

  4. Android自定义控件:打造自己的QQ空间主页

    前面已经实现过仿QQ的List抽屉效果以及仿QQ未读消息拖拽效果,具体请见: Android自定义控件:类QQ抽屉效果 Android自定义控件:类QQ未读消息拖拽效果 趁热打铁,这次我们实现QQ空间 ...

  5. Android自定义控件全览(一)

    Android自定义控件总结(一) 目的:收集和整理所有的Android自定义控件 文章目录 Android自定义控件总结(一) 前言 一.面包屑布局(BreadCrumbView) 1.自定义Bre ...

  6. 【Android 应用开发】 ActionBar 基础

    作者 : 万境绝尘 (octopus_truth@163.com) 转载请注明出处 : http://blog.csdn.net/shulianghan/article/details/3920439 ...

  7. Android 自定义控件打造史上最简单的侧滑菜单

    侧滑菜单在很多应用中都会见到,最近QQ5.0侧滑还玩了点花样~~对于侧滑菜单,一般大家都会自定义ViewGroup,然后隐藏菜单栏,当手指滑动时,通过Scroller或者不断的改变leftMargin ...

  8. 介绍几个好用的android自定义控件

    首先看效果图, 看下这两个界面,第一个中用到了一个自定义的FlowRadioGroup,支持复合子控件,自定义布局: 第二个界面中看到了输入的数字 自动4位分割了吧:也用到了自定义的DivisionE ...

  9. android自定义组件属性,android自定义控件并添加属性的方法以及示例

    安卓系统为我们提供了丰富的控件,但是在实际项目中我们仍然需要重新通过布局来实现一些效果,比如我们需要一个上面图标,下面文字的button,类似于下面这样的: 最直接的解决办法是通过将imageview ...

  10. 自定义控件android特效,Android自定义控件eBook实现翻书效果实例详解

    本文实例讲述了Android自定义控件eBook实现翻书效果的方法.分享给大家供大家参考,具体如下: 效果图: Book.java文件: package com.book; import androi ...

最新文章

  1. [转]WinForm下Splash(启动画面)制作
  2. ajax java 插件_对JQuery中Ajax应用与jQuery插件的理解与笔记
  3. RabbitMQ从安装到使用
  4. ICCV 2019 | 基于无标签单目视频序列的单帧三维人体姿态估计算法
  5. Thrift入门及Java实例演示
  6. react --- 隔代传递参数的三种方式
  7. 盘点十个超级实用的 JS 特性
  8. LCA求解的四种模板
  9. cisco 交换机vlan-trunk的配置详解及应用实例:
  10. 转载自《读者》--您也吻我一下好吗
  11. AcWing 195. 骑士精神
  12. 浏览器跨域问题(jsonp)——jsonp详解
  13. 我们奋斗着并将持续奋斗 ----暨清华D-Lab创新基地揭牌仪式
  14. Nginx源码分析 - 基础数据结构篇 - 缓冲区结构 ngx_buf.c(04)
  15. android selector 开始自定义样式
  16. selenium模拟点击的几种方法探讨
  17. python烧录单片机_mac实现烧写51单片机
  18. 我谈阶梯博弈(Staircase Nim)
  19. 嵌入式计算机课程设计,嵌入式系统设计课设报告.doc
  20. logical exclusive 与 physical exclusive 的区别

热门文章

  1. jupyter notebook 修改主题、字体、字号等
  2. 213.打家劫舍II(力扣leetcode) 博主可答疑该问题
  3. java 协变 逆变_JAVA中的协变与逆变
  4. mysql如何进行宿舍分配_手把手教你做一个Jsp Servlet Mysql实现的学生宿舍管理系统...
  5. selenium-js
  6. 【转】keil5 missing close quote 错误解决
  7. leetcode 85. Maximal Rectangle
  8. 1052. Linked List Sorting (25)再
  9. xcode 调试提示
  10. treeview实例