[原创]自定义BaseAcitivity的实现,统一activity的UI风格样式
<?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" > <RelativeLayout
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#44550000" /> <RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#44005500" /> </LinearLayout>
自定义的theme,去掉ActionBar:
<style name="AppThemeNoActionBar" parent="AppBaseTheme" >
<item name= "android:windowActionBar" >false </item>
<item name= "android:windowNoTitle" >true </item>
</style >
package cn.carbs.testandroidbaseactivity; public class BaseActivity extends Activity{ protected RelativeLayout content;
protected int colorPrimary ;
protected int colorPrimaryDark ;
protected int colorAccent ; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
super.setContentView(getBaseActivityLayout());
TypedArray array = obtainStyledAttributes( new int[]{R.attr.colorPrimary, R.attr. colorPrimaryDark, R.attr.colorAccent});
colorPrimary = array.getColor(0, 0xFF1473AF);
colorPrimaryDark = array.getColor(1, 0xFF11659A);
colorAccent = array.getColor(2, 0xFF3C69CE);
array.recycle();
} protected int getBaseActivityLayout() {
return R.layout.activity_base;
} @Override
public void setContentView(int layoutResID) {
//使用如下方法可以将layoutResID对应的 xml资源的view解析出来,并添加到R.id.content中
// getLayoutInflater().inflate(layoutResID, (ViewGroup) this.findViewById(R.id.content));
//使用如下方法可以将layoutResID对应的 xml资源的view解析出来,并添加到R.id.content中
// View.inflate(this, layoutResID, (ViewGroup) this.findViewById(R.id.content));
//使用如下方法可以将layoutResID对应的 xml资源的viewinflate出来,但是没有添加到任何ViewGroup中
// View v = View.inflate(this, layoutResID, null); setContentView(View. inflate(this, layoutResID, null));
} @Override
public void setContentView(View view) {
((ViewGroup) this.findViewById(R.id.content))
.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams. MATCH_PARENT));
} }
3.编写一个Activity使其继承自BaseActivity:
package cn.carbs.testandroidbaseactivity; import android.os.Bundle; public class MainActivity extends BaseActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout. activity_main);
} //可以通过如下代码,覆写BaseActivity中的主界面的布局
@Override
protected int getBaseActivityLayout(){
return R.layout. activity_base_new;
} }
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools= "http://schemas.android.com/tools"
android:layout_width= "match_parent"
android:layout_height= "match_parent"
android:background= "#33333399"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop= "@dimen/activity_vertical_margin"
tools:context= ".MainActivity" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" /> </RelativeLayout>
activity_base.xml
<?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" > <RelativeLayout
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#44550000" /> <RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#44005500" /> </LinearLayout>
activity_base_new.xml
<?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" > <RelativeLayout
android:id="@+id/bar"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#ffffffff" /> <RelativeLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#44005500" /> </LinearLayout>
[原创]自定义BaseAcitivity的实现,统一activity的UI风格样式的更多相关文章
- 统一项目中编码风格(Eclipse Java code format、codetemplate)
在公司内的日常开发过程中,除了需要遵守统一的编码规范之外,还需要对编写的代码做统一的格式化,Eclipse提供了格式化编码的工具,快捷键是:Ctrl+Shift+F. 为了统一项目组的代码风格,建议使 ...
- Activity中UI框架基本概念
Activity中UI框架基本概念 Activity 是应用程序的基本组成部分,提供了可视的界面,UI容器, 与用户进行交互: 具体Acitivity是怎么样显示这些事视图元素以及响应事件交互的. 一 ...
- android开发之在activity中控制另一个activity的UI更新
转自:http://blog.csdn.net/jason0539/article/details/18075293 第一种方法: 遇到一个问题,需要在一个activity中控制另一个acitivit ...
- 用 Prettier 统一团队的代码风格~
使用 prettier 自動調整 JavaScript 樣式 GFM 格式说明 为什么你不能缺少Linter(以及代码美化工具) 使用 prettier 自動調整 JavaScript 樣式 Reac ...
- Android 如何利用Activity的Dialog风格完成弹出框设计
在我们使用Dialog时,如果需要用到很多自己设计的控件,虽然可以让弹出框显示出我们需要的界面,但却无法找到地方完成控制代码的编写,如何解决这个问题呢,我们可以将Activity伪装成Dialog弹出 ...
- Activity + 基础UI
目录 Activity + 基础UI 1. 返回键退出进入应用: 2. home键以后 3. home键退出切换字体 二:AndroidManifest配置theme改变UI效果 三:UI 报错: A ...
- 自定义的IntentFileter 无法找到activity
<intent-filter > <action android:name="com.leo.enjoytime.VIEW"/></intent-fi ...
- android自定义view系列:认识activity结构
标签: android 自定义view activity 开发中虽然我们调用Activity的setContentView(R.layout.activity_main)方法显示View视图,但是vi ...
- 配置springboot在访问404时自定义返回结果以及统一异常处理
在搭建项目框架的时候用的是springboot,想统一处理异常,但是发现404的错误总是捕捉不到,总是返回的是springBoot自带的错误结果信息. 如下是springBoot自带的错误结果信息: ...
随机推荐
- 20 个免费的 Bootstrap 的后台管理模板
之前 OSC 曾经发过多个后台管理界面模板的推荐,例如: 50 个漂亮的后台管理界面模板 25 个精美的后台管理界面模板和布局 分享 6 套超酷的后台管理员界面网站模板 30个优秀的后台管理界面设计案 ...
- ASP.NET MVC学习之过滤器篇(1)
一.前言 继前面四篇ASP.NET MVC的随笔,我们继续向下学习.上一节我们学习了关于控制器的使用,本节我们将要学习如何使用过滤器控制用户访问页面. 二.正文 以下的示例建立在ASP.NET MVC ...
- 创建 kylin Module/Cube
1. 首先要创建 Project 2. 再把Hive 表加载进来: 3. 创建model 3.1. 首先选择或者创建一个project 3.2.创建一个新modle 3.3. 选择数据库 ...
- C#自学系列 - 开篇
2014年即将过去,这一年我参加了不少面试,被问到了很多问题.回来总结下发现自己确实在基础方面有着很多的不足,还有很多东西是我不知道的.遂在下半年购入书籍若干,并系统的加以学习.我目前在看的书是Jon ...
- Lambda应用设计模式
前言 在使用 Lambda 表达式时,我们常会碰到一些典型的应用场景,而从常用场景中抽取出来的应用方式可以描述为应用模式.这些模式可能不全是新的模式,有的参考自 JavaScript 的设计模式,但至 ...
- [游戏模版3] Win32 画笔 画刷 图形
>_<:introduce the functions of define\create\use pen and brush to draw all kinds of line and s ...
- crossplatform---Nodejs in Visual Studio Code 06.新建Module
1.开始 Node.js:https://nodejs.org 2.Moudle js编程中,由于大家可以直接在全局作用域中编写代码,使开发人员可以很容易的新建一个全局变量或这全局模块,这些全局变量或 ...
- python函数的参数
代码: # coding=utf8 # 可以传入任何个参数 def calc(*numbers): sum = 0 for n in numbers: sum = sum + n * n return ...
- Unity3D脚本调用Objective C代码实现游戏内购买
0.开篇吐槽: 一年之内从WP转到iOS,又从iOS转到U3D,真心伤不起. 1.Unity3D脚本调用OC代码的原理: 其实也没啥神秘的,因为OC是和C互通的 ,C#又可以通过DllImport的形 ...
- Easyui-datagrid groupview分组后勾选问题
上面datagrid对应的代码如下: $('#tbCheckOut').datagrid({ title: '待分配库位', iconCls: 'icon-search', width: 1112, ...