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都是自定义标题栏,在自定义标题栏的过程中大部分人可能都是自定义一 ...
随机推荐
- (Python基础)文件操作
对文件操作流程 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 现有文件如下 命名为7 years Once I was seven years old my momma t ...
- .yaml参数文件的编写和使用
一.在ROS底下使用.yaml文件配置参数 在ROS底下用起来还是非常方便的,首先,写一个读参数的函数getParam(),由于参数类型不止一种,所以要使用模板. 具体语句如下: template&l ...
- 在eclipse下,用Maven创建Spring MVC工程
参考链接:https://www.cnblogs.com/yangyxd/p/5955630.html 1.打开Eclipse,Ctrl + N 创建Maven
- 必做作业3:短视频编辑app原型化系统
本app立足于打造短视频分享交流社区,app不仅有视频编辑的功能,还有视频的分享和收藏功能.系统有登录.注册.找回密码的功能,可以进行账号资料管理,并可以管理自己的视频.分享和收藏.系统可以对视频进行 ...
- [Linux]Ubuntu 16.04 远程桌面
来源:http://blog.csdn.net/zz_1215/article/details/77921405 先吐槽一下,网上教的方法都是半桶水,都被教到连接后出现灰屏,只有这个博主(zz_121 ...
- activiti官网实例项目activiti-explorer之扩展流程节点属性2
情景需求:需要查找activiti-explorer项目中获取流程id的方法,然后根据流程id获取相应字段在节点属性中添加内容. 大致流程:拿取整个流程id获取对应表单属性,在页面节点属性中展示对应表 ...
- jquery:input操作
1:让一个或一组单选框取消选择 $(".radio1").attr("checked",false); 2:查看一组单选框有么有被选中一个 $(".r ...
- week05 codelab01 Babel ES6 webpack Nodejsserver等
Babel 他出现的原因就是很多浏览器还未完全兼容ES6 需要将你写的ES6的内容转换成ES5让浏览器兼容运行 ES5和ES6相比出现很多新内容 比如拼接字符串 ES6可以` ` 里面如果引用变量就用 ...
- 移动端目标识别(1)——使用TensorFlow Lite将tensorflow模型部署到移动端(ssd)之TensorFlow Lite简介
平时工作就是做深度学习,但是深度学习没有落地就是比较虚,目前在移动端或嵌入式端应用的比较实际,也了解到目前主要有 caffe2,腾讯ncnn,tensorflow,因为工作用tensorflow比较多 ...
- 阿里云 部署dashboard
本文是基于kubeasz 进行部署安装,将部署心得记录下来.可以查看原文地址: https://github.com/gjmzj/kubeasz/blob/master/docs/guide/dash ...