实现透明状态栏,自定义搜索框,banner实现加载图片,搜索框在banner上
来源:互联网 发布:多功能助手软件 编辑:程序博客网 时间:2024/06/07 19:13
//加依赖compile 'com.youth.banner:banner:1.4.9'在values下的styles修改<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">public class TitleView_homepage extends RelativeLayout { private ImageView fg_homepage_zxingiv; private TextView fg_homepage_zxingtv; private RelativeLayout title_homepage_left; private EditText title_homepage_et; private ImageView fg_homepage_searchiv; private ImageView title_homepage_assistant; private RelativeLayout title_homepage_search; private ImageView fg_homepage_msgiv; private TextView fg_homepage_msgtv; private RelativeLayout title_homepage_right; private ImageView zXingIv; private TextView zXingTv; private ImageView msgIv; private TextView msgTv; private ImageView searchIv; private EditText et; public TitleView_homepage(Context context) { super(context); initView(context); } private void initView(Context context) { zXingIv = findViewById(R.id.title_homepage_zxingiv); zXingTv = findViewById(R.id.title_homepage_zxingtv); msgIv = findViewById(R.id.title_homepage_msgiv); msgTv = findViewById(R.id.title_homepage_msgtv); searchIv = findViewById(R.id.title_homepage_searchiv); et = findViewById(R.id.title_homepage_et); LayoutInflater.from(context).inflate(R.layout.title_homepage_layout, this); } public TitleView_homepage(Context context, AttributeSet attrs) { super(context, attrs); initView(context); } public TitleView_homepage(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public void TitlezxingListener(OnClickListener listener) { findViewById(R.id.title_homepage_left).setOnClickListener(listener); } public void TitleMsgListener(OnClickListener listener) { findViewById(R.id.title_homepage_right).setOnClickListener(listener); } public void setSearchListener(OnClickListener listener) { findViewById(R.id.title_homepage_et).setOnClickListener(listener); } public void setAssistantListener(OnClickListener listener) { findViewById(R.id.title_homepage_assistant).setOnClickListener(listener); } public void setImage() { zXingIv.setImageResource(R.drawable.as4); zXingTv.setTextColor(Color.BLACK); msgIv.setImageResource(R.drawable.as2); msgTv.setTextColor(Color.BLACK); et.setBackgroundColor(Color.GRAY); searchIv.setImageResource(R.drawable.as2); }}public class MainActivity extends AppCompatActivity { private Banner banner; private List<Integer> images = new ArrayList<>();//存放本地图片的ID @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);// 透明状态栏getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
setContentView(R.layout.activity_main);
banner = (Banner) findViewById(R.id.fg_homepage_banner);
setBanner();
}
/** * 显示Banner */
private void setBanner() {
/******显示本地图片********/
//图片加载器中需要用到的path;
images.add(R.drawable.banner_a);
images.add(R.drawable.banner_b);
images.add(R.drawable.banner_c);
images.add(R.drawable.banner_d);
//添加本地mipmap下的图片;
banner.setImageLoader(new ImageLoader() {
@Override
public void displayImage(Context context, Object path, ImageView imageView) {
imageView.setImageResource((Integer) path);
}
});
banner.setImages(images);
banner.start();
}}
主页面布局<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.lx_20171113.MainActivity"> <RelativeLayout android:id="@+id/fg_homepage_title" android:layout_width="match_parent" android:layout_height="200dp"> <com.youth.banner.Banner android:id="@+id/fg_homepage_banner" android:layout_width="match_parent" android:layout_height="match_parent" > </com.youth.banner.Banner> <com.example.lx_20171113.TitleView_homepage android:id="@+id/fg_homepage_head" android:layout_width="match_parent" android:layout_height="80dp"></com.example.lx_20171113.TitleView_homepage> </RelativeLayout></RelativeLayout>
title_homepage_layout布局<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:layout_marginTop="20dp" > <RelativeLayout android:id="@+id/title_homepage_left" android:layout_width="52dp" android:layout_height="match_parent" android:layout_centerVertical="true" > <ImageView android:id="@+id/title_homepage_zxingiv" android:layout_width="36dp" android:layout_height="36dp" android:layout_centerHorizontal="true" android:src="@drawable/as5" /> <TextView android:id="@+id/title_homepage_zxingtv" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:gravity="center" android:text="扫啊扫" android:textSize="10sp" android:textColor="#fff" /> </RelativeLayout> <RelativeLayout android:id="@+id/title_homepage_search" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_toLeftOf="@+id/title_homepage_right" android:layout_toRightOf="@+id/title_homepage_left" android:gravity="center" android:layout_centerVertical="true" > <EditText android:id="@+id/title_homepage_et" android:editable="false" android:layout_width="match_parent" android:layout_height="36dp" android:layout_centerVertical="true" android:background="@drawable/corners_bg" android:hint="联想笔记本电脑" android:textColorHint="#999" android:paddingLeft="60dp" android:focusable="false" /> <ImageView android:id="@+id/title_homepage_searchiv" android:layout_width="26dp" android:layout_height="26dp" android:src="@drawable/as6" android:layout_centerVertical="true" android:layout_marginLeft="16dp" /> <ImageView android:layout_width="26dp" android:layout_height="26dp" android:id="@+id/title_homepage_assistant" android:src="@drawable/as1" android:layout_centerVertical="true" android:layout_marginRight="16dp" android:layout_alignParentRight="true" /> </RelativeLayout> <RelativeLayout android:id="@+id/title_homepage_right" android:layout_width="52dp" android:layout_height="match_parent" android:layout_alignParentRight="true" android:layout_centerVertical="true" > <ImageView android:id="@+id/title_homepage_msgiv" android:layout_width="36dp" android:layout_height="36dp" android:layout_centerHorizontal="true" android:src="@drawable/as3" /> <TextView android:id="@+id/title_homepage_msgtv" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:textSize="10sp" android:text="消息" android:textColor="#fff" android:gravity="center" /> </RelativeLayout></RelativeLayout>
corners_bg在drawable下创建<shape xmlns:android="http://schemas.android.com/apk/res/android"> <!--设置填充颜色 为白色--> <solid android:color="#ffffff"></solid> <corners android:radius="50mm"/></shape>
阅读全文
0 0
- 实现透明状态栏,自定义搜索框,banner实现加载图片,搜索框在banner上
- Banner实现
- 自定义view实现下拉缩放顶部imageview banner和上拉加载
- banner实现图片轮播
- Banner实现图片轮播
- Banner实现图片轮播
- Banner实现图片轮播
- Banner实现图片轮播
- ViewPager + Volley 异步多线程图片加载实现Banner效果
- Banner实现无限轮播Glide加载图片
- 自定义图片轮播(Banner)控件的实现解析
- 简单banner加载网络上的图片
- 自定义JQuery插件(附图片轮播banner实现)
- 自定义View学习二(Banner实现)
- 自定义控件实现banner轮播
- 用jQuery实现banner图片切换
- Android实现Banner图片循环轮播
- 图片轮播,两个imageView实现 banner
- android 广播broadcast
- 深度解读 Tomcat 中的 NIO 模型
- JS回调函数
- 大促下热点数据写(库存扣减解决方案
- js校验map方法
- 实现透明状态栏,自定义搜索框,banner实现加载图片,搜索框在banner上
- 云集微店亿级交易额下的Order子系统架构演变
- Spring AOP 所有切入点指示符详解(execution,within,this,target,args,@within,@target,@args,@annotation)
- java.lang.NoClassDefFoundError: org/apache/hive/service/cli/thrift/TCLIService$Iface
- CSS清除浮动 清除float浮动
- Nginx+Tomcat的WEB项目部署
- 模仿微信摇一摇功能
- Python 2.7 import matplotlib出现UnicodeDecodeError错误
- jquery 计算页面滚动到某个元素的速度