- 浏览: 82048 次
- 性别:
- 来自: 深圳
文章分类
最新评论
-
lijh:
[*][url][/url][flash=200,200][/ ...
Android拦截HOME按键 -
ccnu_ouy520:
有人能详细一点吗?
如何获取Android手机中所有的短信 -
ccnu_ouy520:
写的挺好的,我也看了这篇文章 有几个问题
这个getCont ...
如何获取Android手机中所有的短信 -
guobosheng:
楼主,我只想拦截home键,不想屏蔽它,要怎么改啊?
Android拦截HOME按键 -
aking86:
latty 写道不知 你为何屏蔽Home键?解决什么方面的问题 ...
Android拦截HOME按键
自定义控件 TitleBar
实现步骤:
1.先写好一个公共的自定义控件布局文件 custom_widget.xml 2.在其它布局文件里引用自定义控件(PublicTitleBar) activity_custom.xml 3.写自定义控件的类,主要是提供一些方法 PublicTitleBar.java 4.在 activity 里面设置自定义控件 文字/点击事件等 MainActivity.java
先写好一个公共的自定义控件布局文件 custom_widget.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#FFF000"> <!-- org.aking86.test.userdefinedwidget.MyWidget --> <TextView android:id="@+id/tvTitle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/title" tools:context=".MainActivity" /> <Button android:id="@+id/btnBack" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_centerVertical="true" android:text="@string/back" /> <Button android:id="@+id/btnOK" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="@string/ok" /> </RelativeLayout>
在其它布局文件里引用自定义控件(PublicTitleBar) activity_custom.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<org.aking86.test.userdefinedwidget.PublicTitleBar
android:id="@+id/pub_titlebar"
android:layout_width="fill_parent"
android:layout_height="@dimen/pub_titlebar_height" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/pub_titlebar"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</LinearLayout>
<LinearLayout
android:id="@+id/linearLayout2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/linearLayout1"
android:layout_marginLeft="10dp"
android:layout_marginTop="32dp" >
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:hint="@string/entry_the_title" >
<requestFocus />
</EditText>
<Button
android:id="@+id/btnSetTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/settitle" />
</LinearLayout>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/linearLayout2"
android:layout_alignParentTop="true"
android:layout_marginLeft="48dp"
android:layout_marginTop="200dp"
android:text="@string/hello_world"
tools:context=".MainActivity" />
</RelativeLayout>
写自定义控件的类,主要是提供一些方法 PublicTitleBar.java
package org.aking86.test.userdefinedwidget; import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; public class PublicTitleBar extends RelativeLayout { private View view; private Button btnBack, btnOK; private TextView tvTitle; Context context; public PublicTitleBar(Context context) { super(context); this.context = context; initLayoutInflater(); } public PublicTitleBar(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; initLayoutInflater(); } public PublicTitleBar(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); this.context = context; initLayoutInflater(); } private void initLayoutInflater() { LayoutInflater lInflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); // view = lInflater.inflate(R.layout.custom_widget, this); initView(); } private void initView() { btnBack = (Button) view.findViewById(R.id.btnBack); btnOK = (Button) view.findViewById(R.id.btnOK); tvTitle = (TextView) view.findViewById(R.id.tvTitle); } public void setTitle (String text) { tvTitle.setText(text); } @Override public void setOnClickListener (OnClickListener lsn) { btnBack.setOnClickListener(lsn); btnOK.setOnClickListener(lsn); tvTitle.setOnClickListener(lsn); } }
在 activity 里面设置自定义控件 文字/点击事件等
/** * 设置 自定义控件 */ private void setPublicTitleBar() { PublicTitleBar titleBar = (PublicTitleBar) findViewById(R.id.pub_titlebar); titleBar.setTitle ("Welcome...."); titleBar.setOnClickListener (new OnClickListener() { @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnBack: Toast.makeText(getBaseContext(), "btnBack", Toast.LENGTH_SHORT).show(); break; case R.id.btnOK: Toast.makeText(getBaseContext(), "btnOK", Toast.LENGTH_SHORT).show(); break; case R.id.tvTitle: Toast.makeText(getBaseContext(), "Title...", Toast.LENGTH_SHORT).show(); break; default: Toast.makeText(getBaseContext(), "default...", Toast.LENGTH_SHORT).show(); break; } } }); }
- UserDefinedWidget.zip (648.5 KB)
- 下载次数: 76
发表评论
-
demo-tel
2013-01-21 00:18 0Demo-Tel PhoneStateListener ... -
mobile
2012-12-21 01:21 0mobile -
android学习笔记之Base64编码
2012-12-10 23:31 0Base64 http://blog.sina.com. ... -
Android中对图像进行Base64编码
2012-12-10 23:22 0Android中对图像进行Base64 ... -
android中json转换成List<Map>
2012-11-20 01:07 0android中json转换成List<Map&g ... -
ratingBar demo
2012-10-18 23:54 1554关于 ratingBar 参考 资料写的demo ht ... -
android 屏幕保持唤醒
2012-10-09 22:41 0android 屏幕保持唤醒 http://www.cnb ... -
Android系统在超级终端下必会的命令大全
2012-10-05 11:09 1296[教程] Android系统在超级终端下必会的命令大全 ... -
360
2012-07-18 23:35 0写道 package org.android; ... -
android工具箱
2012-04-08 23:40 0android工具箱 -
droiddraw 21 布局工具
2012-03-28 23:17 0droiddraw 21 布局工具 -
Android通讯录
2012-03-26 00:29 0下面展示一段在Android1.5上读取手机通讯录的代码1 ... -
viewPager
2012-03-21 06:12 2005ViewPager MainActivity ... -
android应酬资料
2012-03-15 01:28 901android面试资料。收集的 ... -
android 资料
2012-03-15 01:08 12711.view如何刷新?简述什么是双缓冲?andro ... -
android杀进程方法
2012-02-29 01:15 2155android杀进程方法 源文: http://www.cn ... -
android手机设置自己喜欢的铃声
2012-02-26 18:51 2090存放手机铃声的的路径(三星 I8150 手机): /sys ... -
如何删除android手机自带的系统程序
2012-02-24 00:23 2630操作步骤: 工具准备: DooMLoRD , (Sup ... -
Android Mms 源码结构
2012-02-20 01:12 2349Android Mms 源码结构 源文:http:// ... -
读取android手机流量信息
2012-01-29 00:39 1387参考: http://www.2cto.com/kf/2011 ...
相关推荐
Android自定义控件开发入门与实战从自定义基础到实战的讲解。一步步深入。适合有一定Android基础的读者。本压缩包中自带了推荐的pdf阅读器。大家要是喜欢这本文档,推荐去京东,天猫,当当买支持一下默默付出的作者...
《Android自定义控件开发入门与实战》高清影印版,带目录,拒绝压缩包加密坑钱,内容深入浅出,对于有Android自定义开发需求的非常有帮助
1 本书从动画、绘图、视图三方面介绍Android自定义控件相关知识,内容系统全面,并配以翔实的案例。 2 Android自定义控件涉及动画和色彩,本书将图片地址制作成二维码,可供读者扫描观看。 3 本书适合初高级水平从业...
Android自定义控件示例,基于Android studio 1.0.2。
Android自定义控件详细开发教程
Android 自定义控件简单Demo 图片+文字
Android自定义控件步骤总结 http://www.cnblogs.com/duanxz/p/3625589.html
Android自定义控件源码含APK 仿Material Design风格,在低版本android环境上面实现高版本中的按钮等UI控件,视觉效果提升,本源码将向你介绍一些方法,实现这种效果。注:本源码中使用的控件是原作者已经封装好的,...
《Android自定义控件入门到实战》源码
android自定义控件
这是我写的 Android 自定义控件入门 这个小教程的例子源码,十分基础,用了同一个例子的不同写法和扩展,简单明了的讲解了View的重写,教程请去我的博客,地址为:...希望大家能通过简单的例子学到东西,举一反三。...
Android 组合控件,用自定义方式实现,非简单重写adapter。同时包含了点击事件的响应。
详细讲解自定义控件文章的配套代码!文章地址:http://blog.csdn.net/dinglin_87/article/details/7431545
android 自定义控件 小球的圆周运动 canvas绘出
Android自定义控件源码.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
教程名称: 尚硅谷Android视频教程《自定义控件》Android自定义控件,是中高级程序员必须熟练掌握的技术之一。本套视频涵盖了安卓自定义开发过程中所有的技术问题,课程中讲授的例子全部来源于企业。学习本套视频后...
Android自定义控件之滑动开关 Android自定义控件之滑动开关 http://blog.csdn.net/eeeduo/article/details/37606567
android自定义控件CircleImageVIew的使用举例
这个资源是工作中使用到的自定义控件及一些开源框架收集,挺不错的。
android自定义控件LinkTextView实现