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設置,如: