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都是自定义标题栏,在自定义标题栏的过程中大部分人可能都是自定义一 ...
随机推荐
- mysql安装密码策略插件
https://blog.csdn.net/kk185800961/article/details/79447754 注意linux安装密码策略的插件 validate_password.so
- bootstrap-datetimepicker 时间配置,包含颜色
if ($('.isdatetimepicker')!=undefined&&$('.isdatetimepicker').datetimepicker!=undefined) { / ...
- 没有upcast 也不会发生多态
class A{ public: virtual void f(){ cout << "A::f()"<<endl;} }; class B:public ...
- java学习--Iterable 和 Iterator
Iterable Iterable :故名思议,实现了这个接口的集合对象支持迭代,是可迭代的. 一个集合对象要表明自己支持迭代,能有使用foreach语句的特权,就必须实现Iterable接口,表明我 ...
- centos7.4下的KVM虚拟机安装使用
本来是用的vmware,不过后来想试下KVM,想着装个ZSTACK也行,结果zstack使用网络安装没搞明白,把物理机系统毁了,这下彻底完蛋了,只好还装个centos了,但是又不想用VMWARE就想起 ...
- 【400】numpy.pad 为数组加垫(迷宫类题目)
参考:Numpy学习——数组填充np.pad()函数的应用 举例说明: import numpy as np a = np.zeros((3, 4), dtype=int) a array([[0, ...
- javascript正则表达式分组捕获理解
我们先来看一段js代码: var rquickExpr = /^(?:(<[\w\W]+>)[^>]*|#([\w-]*))$/; console.log(rquickExpr.ex ...
- 解题(Solution -4Sum)
Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...
- 使用netty HashedWheelTimer构建简单延迟队列
背景 最近项目中有个业务,需要对用户新增任务到期后进行业务处理.使用定时任务定时扫描过期时间,浪费资源,且不实时.只能使用延时队列处理. DelayQueue 第一想到的是java自带的延时队列del ...
- LINUX | 谷歌云开启SSH及设置root密码
一.设置root密码 1.先选择从浏览器打开ssh连接服务器 2.切换到root账号 sudo -i 3.设置root密码 passwd 然后会要求输入新密码,然后再重复一次密码,输入密码的时候不会显 ...