android 自定义title
package com.xiangyu.su; import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast; public class BasicActivity extends Activity implements OnClickListener {
private TextView mTitleTextView;
private Button mBackwardButton;
private Button mForwardButton;
private FrameLayout mContentLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setupViews();
}
private void setupViews(){
super.setContentView(R.layout.activity_title);
mTitleTextView=(TextView) findViewById(R.id.text_title);
mContentLayout=(FrameLayout) findViewById(R.id.layout_content);
mBackwardButton=(Button) findViewById(R.id.button_backward);
mForwardButton=(Button) findViewById(R.id.button_forward);
mBackwardButton.setOnClickListener(this);
mForwardButton.setOnClickListener(this);
}
protected void showBackwardView(int backwardResid,boolean show){
if(mBackwardButton!=null){
if(show){
mBackwardButton.setText(backwardResid);
mBackwardButton.setVisibility(View.VISIBLE);
}else{
mBackwardButton.setVisibility(View.INVISIBLE);
}
}
}
protected void showForwardView(int forwardResid,boolean show){
if(mForwardButton!=null){
if(show){
mForwardButton.setVisibility(View.VISIBLE);
mForwardButton.setText(forwardResid);
}else{
mForwardButton.setVisibility(View.INVISIBLE);
}
}
}
private void onBackward(View backwardView){
Toast.makeText(this, "返回", Toast.LENGTH_SHORT).show();
}
protected void onForward(View forwardView) {
Toast.makeText(this, "提交", Toast.LENGTH_LONG).show();
}
@Override
public void setTitle(int titleId) {
mTitleTextView.setText(titleId);
} @Override
public void setTitle(CharSequence title) {
mTitleTextView.setText(title);
} @Override
public void setTitleColor(int textColor) {
mTitleTextView.setTextColor(textColor);
} @Override
public void setContentView(int layoutResID) {
mContentLayout.removeAllViews();
View.inflate(this, layoutResID, mContentLayout);
onContentChanged();
} @Override
public void setContentView(View view) {
mContentLayout.removeAllViews();
mContentLayout.addView(view);
onContentChanged();
} /* (non-Javadoc)
* @see android.app.Activity#setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
@Override
public void setContentView(View view, LayoutParams params) {
mContentLayout.removeAllViews();
mContentLayout.addView(view, params);
onContentChanged();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button_backward:
onBackward(v);
break;
case R.id.button_forward:
onForward(v);
break; default:
break;
}
} }
<?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="match_parent"
android:orientation="vertical" >
<include layout="@layout/layout_titlebar"/> <FrameLayout
android:id="@+id/layout_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF"> </FrameLayout> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_titlebar"
android:layout_width="match_parent"
android:layout_height="52dp"
android:background="#ed4255" >
<TextView
android:id="@+id/text_title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center"
android:singleLine="true"
android:text="标题栏"
android:textColor="#ffffffff"
android:textSize="20dp"/>
<Button
android:id="@+id/button_backward"
android:layout_width="60dp"
android:layout_height="match_parent"
android:background="@drawable/title_button_selector"
android:drawableLeft="@mipmap/back_arrow"
android:drawablePadding="6dp"
android:gravity="center"
android:paddingLeft="5dp"
android:singleLine="true"
android:text="返回"
android:textColor="#ffffffff"
android:textSize="18dp"
android:visibility="invisible"/>
<Button
android:id="@+id/button_forward"
android:layout_width="60dp"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:background="@drawable/title_button_selector"
android:drawablePadding="6dp"
android:gravity="center"
android:paddingLeft="5dp"
android:singleLine="true"
android:text="提交"
android:textColor="#ffffffff"
android:textSize="18dp"
android:visibility="invisible"/>
</RelativeLayout>
使用方法:
继承这个activity,重写onclick()方法
android 自定义title的更多相关文章
- Android 自定义title 之Action Bar
Android 自定义title 之Action Bar 2014-06-29 飞鹰飞龙... 摘自 博客园 阅 10519 转 25 转藏到我的图书馆 微信分享: Action Ba ...
- Android 自定义title样式
requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性.参数是Window类中定义的常量.一.枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需 ...
- android 自定义title 报错 You cannot combine custom titles with other title feat
solution: http://www.apkbus.com/android-80416-1-1.html http://www.eoeandroid.com/forum.php?mod=viewt ...
- (转)Android 自定义标题栏(title栏)
转:http://blog.csdn.net/jamin0107/article/details/6715678 第一步,向实现自定义标题栏,需要在onCreate方法里这样写 requestWind ...
- Android自定义View4——统计图View
1.介绍 周末在逛慕课网的时候,看到了一张学习计划报告图,详细记录了自己一周的学习情况,天天都是0节课啊!正好在学习Android自定义View,于是就想着自己去写了一个,这里先给出一张慕课网的图,和 ...
- Android 自定义ListView
本文讲实现一个自定义列表的Android程序,程序将实现一个使用自定义的适配器(Adapter)绑定 数据,通过contextView.setTag绑定数据有按钮的ListView. 系统显示列表(L ...
- Android 自定义表格显示数据
Android 自定义TextView控件,用来组成表格方便数据的展示. 首先看一下效果 样式不是很好看,需要用的可以自己优化一下. 实现方式很简单. 1.自定义控件 MyTableTextView ...
- Android自定义标题栏
预览一下效果: 素材: 新建一个布局title_bar.xml,代码如下: <?xml version="1.0" encoding="utf-8"?&g ...
- android自定义UI模板图文详解
不知道大家在实际开发中有没有自定义过UI模板?今天花时间研究了一下android中自定义UI模板,与大家分享一下. 每个设计良好的App都是自定义标题栏,在自定义标题栏的过程中大部分人可能都是自定义一 ...
随机推荐
- openssl error while loading serial number
unable to load number from D:/Program Files/OpenSSL-Win64/bin/demoCA/serialerror while loading seria ...
- iOS解决cell重用问题
在写sina 微博界面的过程中使用到了cell,那么就是在cell上添加一些控件,但是由于每条微博的内容都是不同的,所以在显示的过程中,出现了内容重叠的问题,其实就是UITableViewCell重用 ...
- IntelliJ IDEA 关闭多余项目
在开发中 一个项目中可能会有多个子项目,切换起来比较麻烦,需要将用不到的项目关掉 1.就是关闭一个Project中多个module的一个 2.右击要关闭项目,选中弹出窗口中的 Load/Unload ...
- 6.2 集合和映射--集合Set->底层基于链表实现
在6.1中我们实现了底层基于二叉搜索树的集合,本节就底层如何基于链表实现进行学习,注意:此处的链表是之前自己封装的. 1.集合set相关功能 1.1 add()的不同 用于链表本身没有去重的效果,因此 ...
- 201772020113 李清华《面向对象程序设计(java)》第18周学习总结
1.实验目的与要求 (1) 综合掌握java基本程序结构: (2) 综合掌握java面向对象程序设计特点: (3) 综合掌握java GUI 程序设计结构: (4) 综合掌握java多线程编程模型: ...
- TinkPHP框架学习-01基本知识
1-----目录结构 2-----访问地址 3-----MVC开发 一 目录结构 |--Application 程序文件夹 |--Common 公共方法函数 |--Home 模块 |也可以自 ...
- nodejs + express + express-session + redis
nodejs + express + express-session + redis 标题似乎又是不太对,大家领会精神哈 Express 安装express-generator,然后用它来创建一个工程 ...
- JDBC数据库连接参数备忘
database driver url remark MySql com.mysql.jdbc.Driver jdbc:mysql://localhost:3306/xxx mysql-connect ...
- requests和session的区别
简单说 request对象和session对象的最大区别是生命周期. -request request对象的生命周期是针对一个客户端(说确切点就是一个浏览器应用程序)的一次请求,当请求完毕之后,req ...
- 在Centos7上安装wxPython4.0.4
在linux上安装wxPython4.0.4时需要gtk+2.0,在安装wxPython4.0.4遇到以下错误. linux上是用pip安装wxPython4.0.4的,执行命令如下: pip ins ...