图标改变颜色:Drawable的变色,让Android也能有iOS那么方便的图片色调转换,就像同一个图标,但是有多个地方使用,并且颜色不一样,就可以用这个方法了。

搜索框: 一般是EditText实现,本文 实现 TextView图片和文字居中,键盘搜索。
来看看效果图:
图标改变颜色:第一个界面的左边(二维码)和右边(更多)两个实现,我放进去的图片是黑色的,显示出来是白色的。
搜索框:第一个界面的图片和文字居中,还可以设置间距,第二个见面搜索设置键盘搜索按钮,点击搜索监听事件,清除内容的图标。
搜索框布局:
<!-- 搜索图标设置 左边 android:drawableLeft="@mipmap/icon_search" android:drawablePadding="5dp" 图标和文字的间距 右边 android:drawableRight="@mipmap/round_close" android:paddingRight="8dp" android:imeOptions="actionSearch" 设置成搜索按钮 --> <EditText android:id="@+id/search_text" android:layout_width="0dp" android:layout_weight="1" android:layout_height="30dp" android:hint="输入要搜索的商品" android:background="@drawable/search_gray" android:layout_marginTop="10dp" android:layout_marginLeft="9dp" android:textSize="12sp" android:drawableLeft="@mipmap/icon_search" android:paddingLeft="9dp" android:drawablePadding="5dp" android:drawableRight="@mipmap/round_close" android:paddingRight="8dp" android:imeOptions="actionSearch" android:maxLines="1" android:singleLine="true" />
键盘监听:
searchText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((actionId == 0 || actionId == 3) && event != null) {
//提示搜索内容
Toast.makeText(SearchActivity.this,searchText.getText().toString(),Toast.LENGTH_LONG).show();
//可以跳转搜索页面
/* Intent intent= new Intent(SearchActivity.this,SearchWebViewActivity.class);
intent.putExtra("model",model);
intent.putExtra("search",searchText.getText().toString());
startActivity(intent);
finish();*/
}
return false;
}
});
首页布局:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:minHeight="45dp" android:orientation="horizontal" android:gravity="center_vertical" > <ImageButton android:id="@+id/home_left_scan" android:layout_width="wrap_content" android:layout_height="wrap_content" android:paddingRight="19dp" android:paddingTop="3dp" android:paddingBottom="3dp" android:paddingLeft="11dp" android:layout_centerVertical="true" android:background="#00000000" /> <com.zhangqie.searchbox.view.DrawableTextView android:id="@+id/home_search" android:layout_width="match_parent" android:layout_height="28dp" android:layout_weight="1" android:background="@drawable/search_view_background" android:gravity="center_vertical" android:maxLines="1" android:text="输入搜索相关内容" android:drawableLeft="@mipmap/icon_search" android:textSize="12sp" android:drawablePadding="11dp" /> <ImageButton android:id="@+id/home_right_more" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:layout_alignParentRight="true" android:paddingRight="15dp" android:paddingTop="3dp" android:paddingBottom="3dp" android:paddingLeft="15dp" android:background="#00000000" /> </LinearLayout>
自定义DrawableTextView:(文字图标居中)
public class DrawableTextView extends TextView {
public DrawableTextView(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
}
public DrawableTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public DrawableTextView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
Drawable[] drawables = getCompoundDrawables();
// 得到drawableLeft设置的drawable对象
Drawable leftDrawable = drawables[0];
if (leftDrawable != null) {
// 得到leftDrawable的宽度
int leftDrawableWidth = leftDrawable.getIntrinsicWidth();
// 得到drawable与text之间的间距
int drawablePadding = getCompoundDrawablePadding();
// 得到文本的宽度
int textWidth = (int) getPaint().measureText(getText().toString().trim());
int bodyWidth = leftDrawableWidth + drawablePadding + textWidth;
canvas.save();
canvas.translate((getWidth() - bodyWidth) / 2, 0);
}
super.onDraw(canvas);
}
}
有需要的朋友点击下载源码哦!
https://github.com/DickyQie/android-basic-control/tree/search-box
总结
以上所述是小编给大家介绍的Android 改变图标原有颜色和搜索框的实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
# android
# 图标颜色
# 搜索框
# Android如何动态改变App桌面图标
# Android实现动态改变app图标的示例代码
# Android实现修改状态栏背景、字体和图标颜色的方法
# Android 修改app图标和名称的方法
# Android App更改应用的图标的实现方法
# android开发修改状态栏背景色和图标颜色的示例
# Android改变ExpandableListView的indicator图标实现方法
# Android动态修改应用图标与名称的方法实例
# 第一个
# 小编
# 就像
# 相关内容
# 还可以
# 多个
# 在此
# 可以用
# 第二个
# 给大家
# 能有
# 来看看
# 自定义
# 点击下载
# 跳转
# 首页
# 所述
# 给我留言
# 感谢大家
# 设置成
相关文章:
制作充值网站的软件,做人力招聘为什么要自己交端口钱?
阿里云高弹*务器配置方案|支持分布式架构与多节点部署
建站之星与建站宝盒如何选择最佳方案?
如何解决ASP生成WAP建站中文乱码问题?
建站之星安装提示数据库无法连接如何解决?
车管所网站制作流程,交警当场开简易程序处罚决定书,在交警网站查询不到怎么办?
枣阳网站制作,阳新火车站打的到仙岛湖多少钱?
高防服务器租用如何选择配置与防御等级?
建站主机是否等同于虚拟主机?
网站制作大概要多少钱一个,做一个平台网站大概多少钱?
天河区网站制作公司,广州天河区如何办理身份证?需要什么资料有预约的网站吗?
如何有效防御Web建站篡改攻击?
上海网站制作网站建设公司,建筑电工证网上查询系统入口?
如何用搬瓦工VPS快速搭建个人网站?
海南网站制作公司有哪些,海口网是哪家的?
,南京靠谱的征婚网站?
如何自己制作一个网站链接,如何制作一个企业网站,建设网站的基本步骤有哪些?
如何在云指建站中生成FTP站点?
如何用景安虚拟主机手机版绑定域名建站?
惠州网站建设制作推广,惠州市华视达文化传媒有限公司怎么样?
h5网站制作工具有哪些,h5页面制作工具有哪些?
如何快速生成ASP一键建站模板并优化安全性?
如何在IIS中新建站点并配置端口与物理路径?
手机钓鱼网站怎么制作视频,怎样拦截钓鱼网站。怎么办?
如何在腾讯云服务器快速搭建个人网站?
建站之星价格显示格式升级,你的预算足够吗?
宝塔建站助手安装配置与建站模板使用全流程解析
宝塔建站教程:一键部署配置流程与SEO优化实战指南
建站主机服务器选型指南与性能优化方案解析
Python文件管理规范_工程实践说明【指导】
香港服务器网站推广:SEO优化与外贸独立站搭建策略
移民网站制作流程,怎么看加拿大移民官网?
网站制作说明怎么写,简述网页设计的流程并说明原因?
北京制作网站的公司排名,北京三快科技有限公司是做什么?北京三快科技?
移动端手机网站制作软件,掌上时代,移动端网站的谷歌SEO该如何做?
如何快速使用云服务器搭建个人网站?
红河网站制作公司,红河事业单位身份证如何上传?
建站之星×万网:智能建站系统+自助建站平台一键生成
广东企业建站网站优化与SEO营销核心策略指南
如何正确下载安装西数主机建站助手?
,交易猫的商品怎么发布到网站上去?
建站之星如何实现PC+手机+微信网站五合一建站?
建站之星后台搭建步骤解析:模板选择与产品管理实操指南
如何在万网主机上快速搭建网站?
在线ppt制作网站有哪些软件,如何把网页的内容做成ppt?
建站之星在线客服如何快速接入解答?
自助网站制作软件,个人如何自助建网站?
建站主机默认首页配置指南:核心功能与访问路径优化
php8.4新语法match怎么用_php8.4match表达式替代switch【方法】
韩国代理服务器如何选?解析IP设置技巧与跨境访问优化指南
*请认真填写需求信息,我们会在24小时内与您取得联系。