• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > android 自定义title,androidtitle

android 自定义title,androidtitle

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了android 自定义title,android notitle,android studio title,android 不显示title,android title设置等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

android 自定义title,androidtitle


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()方法

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • android 自定义title,androidtitle

相关文章

  • 2017-05-26Android环境搭建和编写helloworld,androidhelloworld
  • 2017-05-26android eclipse关联源码,以及源码(代码)以及jar查看软件,androideclipse
  • 2017-05-26Android 查看自己的keystore的别名及相关信息,androidkeystore
  • 2017-05-26老人桌面===花花绿绿的桌面,老人桌面
  • 2017-05-26node.js 通过ajax上传图片
  • 2017-05-26安卓第十三天笔记-服务(Service),安卓第十三天
  • 2017-05-26Handler消息传递机制(一)
  • 2017-05-26分析google的multidex库,googlemultidex库
  • 2017-05-26【React Native开发】React Native控件之ToolbarAndroid工具栏控件讲解以及使用(15)
  • 2017-05-26android-webview的使用小结,android-webview

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • GCM(Google Cloud Messaging)推送完全解析,gcmmessaging
    • JSON解析,json在线解析
    • linux2.4.18----25.文件系统的构建
    • Android中MotionEvent的来源和ViewRootImpl
    • setOnLongClickListener中return值,onlongclicklistener
    • Android Studio第一次提交git使用,androidgit
    • 模仿轻仿蘑菇街应用源码,仿蘑菇街源码
    • Winform突然不响应KeyEvent了
    • Android 环境搭建 以及 第一个android 程序的编写,搭建android
    • Android Studio安装指南及genymotion配置

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有