TitleButton
来源:互联网 发布:网络上的白云先生是谁 编辑:程序博客网 时间:2024/05/20 23:59
import android.app.Activity;import android.content.Context;import android.graphics.Color;import android.util.AttributeSet;import android.view.Gravity;import android.view.MotionEvent;import android.view.View;import android.widget.ImageButton;import android.widget.ImageView;import android.widget.LinearLayout;import android.widget.TextView;public class TitleButton extends LinearLayout {public TitleButton(Context context, AttributeSet attr) {super(context, attr);init(context, attr);}private void init(Context context, AttributeSet attr) {final ImageView iv = new ImageView(context);LayoutParams imageParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);iv.setLayoutParams(imageParams);iv.setBackgroundResource(R.drawable.title_img_normal);addView(iv);final TextView tv = new TextView(context, attr);LayoutParams textParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);textParams.setMargins(12, 0, 0, 0);tv.setLayoutParams(textParams);tv.setTextSize(40);tv.setTextColor(Color.WHITE);tv.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);addView(tv);OnTouchListener impassiveListener = new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {return false;}};iv.setOnTouchListener(impassiveListener);tv.setOnTouchListener(impassiveListener);this.setOnTouchListener(new OnTouchListener() {@Overridepublic boolean onTouch(View v, MotionEvent event) {int action = event.getAction();switch (action) {case MotionEvent.ACTION_DOWN:iv.setBackgroundResource(R.drawable.title_img_pressed);tv.setTextColor(Color.rgb(255, 114, 0));break;case MotionEvent.ACTION_UP:case MotionEvent.ACTION_CANCEL:iv.setBackgroundResource(R.drawable.title_img_normal);tv.setTextColor(Color.WHITE);break;default:break;}return false;}});String clickAttr = attr.getAttributeValue("http://schemas.android.com/apk/res/android", "onClick");if (clickAttr == null || clickAttr.length() == 0) {setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {Activity activity = (Activity) getContext();activity.finish();}});}setBackgroundColor(Color.TRANSPARENT);setPadding(23, 10, 0, 10);setGravity(Gravity.CENTER_VERTICAL);}}
阅读全文
0 0
- TitleButton
- swift navigationItem titleButton
- 【新浪微博项目】07--设置navigationItem和自定义TitleButton
- Java集合类详解
- Android原生Sqlite数据库设计
- 3 springboot 热部署问题
- css动画效果:鼠标移上去底部线条从中间往四周动画延伸
- 关于 10 个自增典型例题中例 7 的解释
- TitleButton
- HDU 1175 连连看 (DFS)
- 如何用css实现一条直线渐变效果
- sql注入攻击和防范
- 给出一个不多于5位的正整数,(1) 求出它是几位数(2) 分别打印出每一位数字(3) 按逆序打印出各位数字,例如原数为321,应输出123
- Spring集成junit测试
- css制作导航栏小三角形箭头 .clearance-product-title span.active:after ,.clearance-product-title span:hover:afte
- linux下的/dev/mem设备认识和使用
- go 初始化之路