androidactionbar底部
A. android如何去掉actionbar
当使用Android中的ActionBar控件时,如果想要隐藏上面的ActionBar,可以使用如下的代码:
getSupportActionBar().hide();//隐藏掉整个ActionBar,包括下面的Tabs
上面的代码会将整个ActionBar都隐藏掉,包括ActionBar中的Tab分页标签,如果想要保留分页标签的话,可以使用如下的代码:
ActionBar actionBar = getSupportActionBar();//高版本可以换成 ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowHomeEnabled(false);
//会保留tab标签
另外还有一种更简单的方式来移除ActionBar,在setContent之前调用下面这句,保证没有ActionBar
requestWindowFeature(Window.FEATURE_NO_TITLE);
B. Android如何做类似淘宝那样,把按钮固定底部,点击按钮跳到别的界面,底部按钮不会改变呢
fragment知道吧
创建一个activity,布局是
<?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:background="@color/activity_bg_default"
android:orientation="vertical">
<Fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/material_text_color_black_divider" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="7dp">
<RadioButton
android:id="@+id/bottom_bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="0"
android:button="@null"
android:checked="true"
android:drawableBottom="@drawable/main_bottom_btn1" />
<RadioButton
android:id="@+id/bottom_bar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:tag="1"
android:drawableBottom="@drawable/main_bottom_btn2" />
<ImageButton
android:id="@+id/bottom_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="@color/activity_bg_default"
android:src="@drawable/ic_main_center" />
<RadioButton
android:id="@+id/bottom_bar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="2"
android:button="@null"
android:drawableBottom="@drawable/main_bottom_btn3" />
<RadioButton
android:id="@+id/bottom_bar4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:tag="3"
android:drawableBottom="@drawable/main_bottom_btn4" />
</RadioGroup>
</LinearLayout>
然后会用 就创建四个fragment,在activity利用hide和show的特性对应radiobutton来做点击切换。
不会用立刻去网络,给你上一课,不会的要网络。提问太慢了
C. android 怎么使用windowsplitactionbar
究竟是如何将R.layout.xxx_view.xml这样的布局文件加载到Android系统的view层次结构中的(即我们常说的view树)。
这期间一方面自己研究了下源码,另一方面也在网上搜索了下相关文章,发现了2篇很不错的同主题文章,推荐给大家:
http://blog.csdn.net/qinjuning/article/details/7226787 & http://blog.csdn.net/bigconvience/article/details/28626631。
我们在开发中接触的最早的应该算是Activity.setContentView(int resourceId)方法了,我们知道在Activity的onCreate方法
中调用此方法可以把我们提供的根布局文件加载到activity中并显示出来。很自然地我们就从它开始说起吧,废话不多说上代码:
复制代码
/**
* Set the activity content from a layout resource. The resource will be
* inflated, adding all top-level views to the activity.
*
* @param layoutResID Resource ID to be inflated.
*
* @see #setContentView(android.view.View)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setContentView(int layoutResID) { // 实际上其内部都是delegate给了getWindow()方法
getWindow().setContentView(layoutResID);
initActionBar();
}
/**
* Set the activity content to an explicit view. This view is placed
* directly into the activity's view hierarchy. It can itself be a complex
* view hierarchy. When calling this method, the layout parameters of the
* specified view are ignored. Both the width and the height of the view are
* set by default to {@link ViewGroup.LayoutParams#MATCH_PARENT}. To use
* your own layout parameters, invoke
* {@link #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)}
* instead.
*
* @param view The desired content to display.
*
* @see #setContentView(int)
* @see #setContentView(android.view.View, android.view.ViewGroup.LayoutParams)
*/
public void setContentView(View view) {
getWindow().setContentView(view);
initActionBar();
}
/**
* Set the activity content to an explicit view. This view is placed
* directly into the activity's view hierarchy. It can itself be a complex
* view hierarchy.
*
* @param view The desired content to display.
* @param params Layout parameters for the view.
*
* @see #setContentView(android.view.View)
* @see #setContentView(int)
*/
public void setContentView(View view, ViewGroup.LayoutParams params) {
getWindow().setContentView(view, params);
initActionBar();
}
/**
* Add an additional content view to the activity. Added after any existing
* ones in the activity -- existing views are NOT removed.
*
* @param view The desired content to display.
* @param params Layout parameters for the view.
*/
public void addContentView(View view, ViewGroup.LayoutParams params) {
getWindow().addContentView(view, params);
initActionBar();
}
复制代码
我们可以看到setContentView方法内部都delegate给了getWindow()方法,这里顺便也把addContentView提及了下,setXXX有
替换的意思,addXXX则是往后面在加一个,即以前的还在。紧接着我们看下Activity里的window是咋来的吧,代码如下:
复制代码
private Window mWindow; // Activity的一个字段
/**
* Retrieve the current {@link android.view.Window} for the activity.
* This can be used to directly access parts of the Window API that
* are not available through Activity/Screen.
*
* @return Window The current window, or null if the activity is not
* visual.
*/
public Window getWindow() {
return mWindow;
}
final void attach(Context context, ActivityThread aThread, Instrumentation instr, IBinder token,
Application application, Intent intent, ActivityInfo info, CharSequence title,
Activity parent, String id, NonConfigurationInstances lastNonConfigurationInstances,
Configuration config) {
attach(context, aThread, instr, token, 0, application, intent, info, title, parent, id,
lastNonConfigurationInstances, config);
}
final void attach(Context context, ActivityThread aThread,
Instrumentation instr, IBinder token, int ident,
Application application, Intent intent, ActivityInfo info,
CharSequence title, Activity parent, String id,
NonConfigurationInstances lastNonConfigurationInstances,
Configuration config) {
attachBaseContext(context);
mFragments.attachActivity(this, mContainer, null);
mWindow = PolicyManager.makeNewWindow(this); // 注意这行代码,这里实际上创建了一个PhoneWindow的实例
mWindow.setCallback(this); // window对象里的Callback接口的实现是Activity
mWindow.getLayoutInflater().setPrivateFactory(this);
if (info.softInputMode != WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED) {
mWindow.setSoftInputMode(info.softInputMode);
}
if (info.uiOptions != 0) {
mWindow.setUiOptions(info.uiOptions);
}
mUiThread = Thread.currentThread();
mMainThread = aThread;
mInstrumentation = instr;
mToken = token;
mIdent = ident;
mApplication = application;
mIntent = intent;
mComponent = intent.getComponent();
mActivityInfo = info;
mTitle = title;
mParent = parent;
mEmbeddedID = id;
= lastNonConfigurationInstances;
mWindow.setWindowManager(
(WindowManager)context.getSystemService(Context.WINDOW_SERVICE),
mToken, mComponent.flattenToString(),
(info.flags & ActivityInfo.FLAG_HARDWARE_ACCELERATED) != 0);
if (mParent != null) {
mWindow.setContainer(mParent.getWindow());
}
mWindowManager = mWindow.getWindowManager();
mCurrentConfig = config;
}
复制代码
这里我们顺便解释下Window、Activity、View的区别和联系:
首先Window是个抽象类,封装了顶层Window样式和行为的策略类,它的实例被用作顶层view加到window manager里面,它提供了
标准的UI策略,如背景、标题栏、默认的key处理逻辑等等。在Android系统中有一个唯一的实现PhoneWindow,当我们需要window的
时候就会有一个PhoneWindow的实例被new出来。每个Activity都有一个与之关联的window对象,Activity在其上绘制其UI。
Window对象里又有一个mDecor对象,它是window里的顶层view(也就是说view的层次结构从它开始,它是view树的根)。
更多的解释可以参考这个问题: android-window 。
D. Android知识串讲(1) 底部导航栏遮挡|转屏锁定|ActionBar隐藏
方法一:隐藏
Android中布局内容被底部系统导航栏遮挡
方法二:内容上移
Android手机底部NavigationBar挡住界面的解决方法
在 Manifest.xml 文件中设腔备置 Activity 的属性
Android布局界面隐藏顶部导航栏
Android隐藏和显示虚拟导航栏
Android 获取手机存储总大小,系统占用空间
Android 获取稿圆备屏幕宽度和高度的几种键毁方法
Android 获取电池相关信息
Android电量计重要的类及函数介绍
安卓5.0后获取所有运行的进程信息
Android获取内存(RAM)大小信息
android 几种杀进程的方式
Android开发中 获取App缓存大小以及清除缓存
Looper.getMainLooper()使用误区
Android中通过资源文件获取drawable的几种方法
Fragment向Activity传递值
注意:
E. android 的action bar有什么作用
下面是一个actionbar的使用截图,来源于android学习手册,360手机助手中可下载,里面有108个例子,源码还有文档
Action bar是一个标识应用程序和用户位置的窗口功能,并且给用户提供操作和导航模式。在大多数的情况下,当你需要突出展现用户行为或全局导航的activity中使用action bar,因为action bar能够使应用程序给用户提供一致的界面,并且系统能够很好根据不同的屏幕配置来适应操作栏的外观。你能够用ActionBar的对象的API来控制操作栏的行为和可见性,这些API被添加在Android3.0(API 级别 11)中。
Action bar的主要目的是:
1.提供一个用于识别应用程序的标示和用户的位置的专用空间。
这个空间的左边是应用的图标或logo,以及Activity的标题。但是,如果是像当前选择的标签这样的标识当前View对象的导航标签,你可以选择删除Activity的标题。
2.在不同的应用程序之间提供一致的导航和视觉体验。
Action bar提供了用于Fragment间切换的内置导航标签。它还提供了一个用于替换导航模式或优化当前视觉效果(如按照不同条件排序的列表)的下拉列表。
3.突出Activity的关键操作(如“搜索”、“创建”、“共享”等),并且在可预见的方法内给用户提供快捷的访问。
对于关键的用户操作,你能够通过把选项菜单项作为操作项直接放到操作栏中,从而提供快捷的访问。操作项目还能提供一个操作窗口,这个窗口给更直接的操作行为提供一个嵌入的窗口部件。没有改进成操作项的菜单项在溢出菜单中还是有效的,用户既可以使用设备上的菜单按钮(设备上有按钮的时候),也可以使用操作栏中的溢出菜单按钮(当设备上不包含菜单按钮时)来显示这些操作项目。
上面的总结一下:Action bar就是替换3.0以前的tittle bar和menu。
图1. Honeycomb Gallery应用中的操作栏,从左边开始,依次是logo、导航选项标签和操作项(在右边插入的一个悬浮菜单按钮)。
Note:If you're looking for information about the contextual action bar for displaying contextual action items, see theMenuguide.
Action Bar Design For design guidelines, read Android Design'sAction Barguide.
添加Action Bar
从Android3.0(API级别 11)开始,Action bar被包含在所有的使用Theme.Hole主题的Activity(或者是这些Activity的子类)中,当targetSdkVersion或minSdkVersion属性被设置为“11”或更大的数值是,这个主题是默认的主题一。如:
[html] view plain print?
<manifest...>
<uses-sdkandroid:minSdkVersion="4"
android:targetSdkVersion="11"/>
...
</manifest>
<manifest ... >
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="11" />
...
</manifest>
在这个例子中,应用程序要求最小的API版本级别是4(Android 1.6),但是它还要求了目标API版本级别是11(Android 3.0)。这样,当应用程序运行在Android3.0或更高的版本上时,系统就会给每个Activity应用holographic 主题,这样,每个Activity就会包含Action bar。
如果你想使用ActionBar API来进行添加导航模式和修改操作栏样式的操作,你应该把minSdkVersion属性设置为“11”或更大的值。有一些方法可以使你的应用支持更旧的Android版本,同时在API等级为11或更高的API等级的机器的使你的应用支持一些Action bar apis。为了保持后向兼容,请参考边框内的内容(边框内容如下)。
Remaining backward-compatible
If you want to provide an action bar in your applicationandremain compatible with versions of Android older than 3.0, you need to create the action bar in your activity's layout (because theActionBarclass is not available on older versions).
To help you, theAction Bar Compatibilitysample app provides an API layer and action bar layout that allows your app to use some of theActionBarAPIs and also support older versions of Android by replacing the traditional title bar with a custom action bar layout.
删除Action bar
如果你不想要Action bar,把Activity的主题设置为Theme.Holo.NoActionBar就可以了,如:
[html] view plain print?
<activityandroid:theme="@android:style/Theme.Holo.NoActionBar">
<activity android:theme="@android:style/Theme.Holo.NoActionBar">
或者使用Action bar的 hide()方法,如下:
[java] view plain print?
ActionBaractionBar=getActionBar();
actionBar.hide();
ActionBar actionBar = getActionBar();
actionBar.hide();
当Action bar隐藏时,系统会调整你的Activity来填充当前有效的屏幕空间。你能够使用show()方法来再次显示操作栏。
在隐藏和删除Action bar时,要当心为了适应被Action bar占用的空间而导致的Activity的重新布局。如果你的Activity有规律的隐藏和显示Action bar,你可能想要使用覆盖模式。覆盖模式在Activity的顶部描画操作栏,而不是在它们所拥有的屏幕的区域。这样,在Action bar隐藏和重新显示时,你的布局保持不变。要使用覆盖模式,就要给Activity创建一个主题,并且把android:windowActionBarOverlay属性设置为true。
提示:如果你有一个删除了Action bar的定制化的Activity主题,它把android:windowActionBar样式属性设置为false。但是,如果你使用了删除Action bar的一个主题,那么,创建窗口将不允许Action bar再显示,因此,你不能在以后给这个Activity添加Action bar---因为getActionBar()方法将返回null。
添加操作项
有些时候,你可能想要让用户直接访问选项菜单中的一个项目,因此你要把应该在Action bar中显示的菜单项作为一个操作项来声明。操作项能够能够包含一个图标或文本标题。如果一个菜单项不作为一个操作项显示,那么系统就会把它放到悬浮菜单中。悬浮菜单既可以通过设备的Menu按钮来显示,也可以在Action bar中一个额外的按钮来显示。
当Activity首次启动时,系统会调用onCreateOptionsMenu()方法给你的Activity组装Action bar和悬浮菜单。在这个回调方法中应该加载在XML文件中定义的菜单项资源,如:
[java] view plain print?
@Override
(Menumenu){
MenuInflaterinflater=getMenuInflater();
inflater.inflate(R.menu.main_activity,menu);
returntrue;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity, menu);
return true;
}
图2. 带有图标和文本标题的两个操作项,和悬浮菜单按钮。
在XML文件中,你能够通过给<item>元素声明android:showAsAction=”ifRoom”属性,请求把一个菜单项作为一个操作项来显示。用这种方式,只在有有效的空间时,菜单项才能显示在Action bar中。如果没有足够的空间,这个菜单项会显示在悬浮菜单中。
如果你的菜单项支持标题和图标---带有android:title和android:icon属性---那么默认情况下,操作项仅显示图标。如果你要显示文本标题,就要给android:showAsAction属性添加withText设置,如: