Andrioid自定义标题栏
2015-09-11 00:00
225 查看
MainActivyty.java
TitleLayout.java
activity_main.xml
title.xml
[code]package com.example.uimyview; import android.app.Activity; import android.os.Bundle; import android.view.Window; public class MainActivity extends Activity{ protected void onCreate(Bundle save) { super.onCreate(save); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); } }
TitleLayout.java
[code]package com.example.uimyview; import android.app.Activity; import android.app.AlertDialog; import android.app.ProgressDialog; import android.content.Context; import android.content.DialogInterface; import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.widget.*; public class TitleLayout extends LinearLayout { private ButOnClickListener listener; public TitleLayout(Context context, AttributeSet attrs) { super(context, attrs); LayoutInflater.from(getContext()).inflate(R.layout.title, this); listener = new ButOnClickListener(); Button back = (Button) findViewById(R.id.back); Button edit = (Button) findViewById(R.id.edit); back.setOnClickListener(listener); edit.setOnClickListener(listener); } private class ButOnClickListener implements OnClickListener { @Override public void onClick(View v) { switch (v.getId()) { case R.id.back: ((Activity) getContext()).finish(); break; case R.id.edit: AlertDialog.Builder dialog = new AlertDialog.Builder(getContext()); dialog.setTitle("提示"); dialog.setMessage("确定退出?"); dialog.setCancelable(false); dialog.setPositiveButton("是", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ((Activity)getContext()).finish(); } }); dialog.setNegativeButton("否", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); // ProgressDialog dialog = new ProgressDialog(getContext()); // dialog.setTitle("提示"); // dialog.setMessage("正在加载...."); dialog.show(); break; } } } }
activity_main.xml
[code]<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" > <com.example.uimyview.TitleLayout android:layout_width="match_parent" android:layout_height="wrap_content" > </com.example.uimyview.TitleLayout> </LinearLayout>
title.xml
[code]<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/title_bg" android:orientation="horizontal" > <Button android:id="@+id/back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/back_bg" android:text="@string/back" android:textColor="#fff" /> <TextView android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_weight="1" android:gravity="center" android:text="This is title" android:textColor="#fff" android:textSize="24sp" /> <Button android:id="@+id/edit" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:background="@drawable/edit_bg" android:text="Edit" android:textColor="#fff" /> </LinearLayout>
相关文章推荐
- VIEWGOOD(远古)在线访谈系统的介绍
- Hadoop系列之五:MapReduce进阶(2)
- Hadoop系列之六:分布式文件系统HDFS
- Hadoop系列之七:分布式文件系统HDFS(2)
- Hadoop系列之八:Hadoop集群
- Hadoop系列之九:Hadoop集群伪分布式模式的实现详解
- Hadoop系列之九:Hadoop集群伪分布式模式的实现详解
- 二叉搜索的 上搜和 下搜
- 链表的中点,是否有环,有环时环的起点,环的长度,链表的长度
- 留言板——列表分页
- 使 div 水平 垂直 居中
- java
- MySQL TEXT类型
- DebugLog.php
- 使用 sphinx 制作简洁而又美观的文档
- 自己在安装MYSQL常见问题
- 天下数据分析浏览器兼容对网站的意义
- openresty如何对url进行解码
- Log4j2.x xml配置文件内容
- Redis官网——如何利用Redis做服务器集群的分布式锁