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. 【C语音基础】printf()用法

    printf() -- 将变量的内容输出到显示器上 四种用法 1.printf("字符串\n"); 2.printf("输出控制符",输出参数); 3.prin ...

  2. flink 学习

    一.运行 SockWordCount例子 1.到官网上下载 flink-1.6.2-bin-hadoop27-scala_2.11.tgz 然后加压出来 2.cd flink-1.6.2 3.打开fl ...

  3. 爬虫之urllib

    一.request模块 1.urlopen()     --返回值为HTTPResponse对象 urlopen(url, data=None, timeout=socket._GLOBAL_DEFA ...

  4. TypeError: Fetch argument 0 has invalid type <type 'int'>, must be a string or Tensor. (Can not convert a int into a Tensor or Operation.)

    6月5日的時候,修改dilated_seg.py(使用tensorflow)出現了報錯: TypeError: Fetch argument 0 has invalid type <type ' ...

  5. --- rk3399/3288 系列平台接mipi 的dts 数据 panel-init-sequence = [] 命令的整法

    https://blog.csdn.net/Shushan1/article/details/87858434 mipi 屏的数据手册 dts sample: &dsi { status = ...

  6. Caused by: java.lang.IllegalArgumentException: argument type mismatch

    下面是我的报错信息 at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java: ...

  7. pycharm+Django+MySQL项目连接数据库中原有数据库

    1.安装驱动 一般会有MySQLdb.pymysql等,因为python版本等问题,我安装的是pymysql. 还可以在项目里安装,File->settings->project 2.在项 ...

  8. js中this的绑定规则及优先级

    一.   this绑定规则 函数调用位置决定了this的绑定对象,必须找到正确的调用位置判断需要应用下面四条规则中的哪一条. 1.1 默认绑定 看下面代码: function foo() { cons ...

  9. 打开fiddler后无法访问网络问题

    https://jingyan.baidu.com/article/f54ae2fc680be81e92b849ed.html 导入证书后,还有一步易遗漏操作: 再次运行fiddler,依次点击Too ...

  10. Namenode启动报错Operation category JOURNAL is not supported in state standby

    org.apache.hadoop.ipc.RemoteException(org.apache.hadoop.ipc.StandbyException): Operation category JO ...