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的更多相关文章

  1. Android 自定义title 之Action Bar

    Android 自定义title 之Action Bar 2014-06-29  飞鹰飞龙...  摘自 博客园  阅 10519  转 25 转藏到我的图书馆   微信分享:   Action Ba ...

  2. Android 自定义title样式

    requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性.参数是Window类中定义的常量.一.枚举常量1.DEFAULT_FEATURES:系统默认状态,一般不需 ...

  3. 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 ...

  4. (转)Android 自定义标题栏(title栏)

    转:http://blog.csdn.net/jamin0107/article/details/6715678 第一步,向实现自定义标题栏,需要在onCreate方法里这样写 requestWind ...

  5. Android自定义View4——统计图View

    1.介绍 周末在逛慕课网的时候,看到了一张学习计划报告图,详细记录了自己一周的学习情况,天天都是0节课啊!正好在学习Android自定义View,于是就想着自己去写了一个,这里先给出一张慕课网的图,和 ...

  6. Android 自定义ListView

    本文讲实现一个自定义列表的Android程序,程序将实现一个使用自定义的适配器(Adapter)绑定 数据,通过contextView.setTag绑定数据有按钮的ListView. 系统显示列表(L ...

  7. Android 自定义表格显示数据

    Android 自定义TextView控件,用来组成表格方便数据的展示. 首先看一下效果 样式不是很好看,需要用的可以自己优化一下. 实现方式很简单. 1.自定义控件 MyTableTextView ...

  8. Android自定义标题栏

    预览一下效果: 素材: 新建一个布局title_bar.xml,代码如下: <?xml version="1.0" encoding="utf-8"?&g ...

  9. android自定义UI模板图文详解

    不知道大家在实际开发中有没有自定义过UI模板?今天花时间研究了一下android中自定义UI模板,与大家分享一下. 每个设计良好的App都是自定义标题栏,在自定义标题栏的过程中大部分人可能都是自定义一 ...

随机推荐

  1. gogs windows

    首先安装 git,然后下载 gogs. 在gogs 文件夹位置 启动. gogs.exe web 打开浏览器,输入 127.0.0.1:3000 ,安装 gogs,注意数据库选择,仓库根目录,管理员帐 ...

  2. 分组密码算法AES-128,192,256 C语言实现第一版

    AES的C语言实现入门版 AES分组密码算法中明文分组位128bits,密钥分组可以为128,192,256bits.AES也是由最基本的变换单位——“轮”多次迭代而成的.我们将 AES 中的轮变换计 ...

  3. Android短信过滤项目中的观察者模式

    观察者模式: 观察者模式定义了对象之间的一对多依赖,当一个对象改变状态时,它的所有依赖者都会收到通知并自动更新. 观察者模式提供了一种对象设计, 让主题和观察者之间松耦合.主题只知道观察者实现了某个接 ...

  4. redis 模糊删除key

    redis-cli KEYS "pattern" | xargs redis-cli DEL Redis keys命令支持模式匹配,但是del命令不支持模式匹配,有时候需要根据一定 ...

  5. for循环,while循环,do while循环

    for循环: for循环格式: for(初始化语句;判断条件语句;控制条件语句) { 循环体语句; } 例子:取五位数各个位数的练习 public static void main(String[] ...

  6. Docker 容器操作命令

    容器是镜像的一个运行实例,镜像是静态的只读文件,而容器带有运行时需要的可写文件层.如果认为虚拟机是模拟运行的一整套操作系统(包括内核.应用运行态环境和其他系统环境)和跑在上面的应用,那么Docker容 ...

  7. open函数新建文件报错

    报错原因很多,我这里只写我遇到的: 给的路径或者文件名中包含了这些字符的:/\:*?"><| 都不行,我说的是Windows平台下的.

  8. FileStream说明

    FileStream(String, FileMode)    FileStream(String path, FileMode) 文件打开模式:(FileMode)包括6个枚举 Append:追加  ...

  9. ARTS打卡计划第二周-Review

    本周review的文章是:https://medium.com/@hakibenita/optimizing-django-admin-paginator-53c4eb6bfca3 改篇文章的题目是: ...

  10. vue 自定义组件销毁

    今天在开发电商vue前端项目时,用户每次登出再换其它用户登录时,页面显示的用户名和左则导航都还是上个用户的,刚开始以为是localStorage中没有清除全局数据,然后在用户点击退出系统时手动清除lo ...