當前位置:首頁 » 安卓系統 » androidactionbar

androidactionbar

發布時間: 2022-08-09 10:10:10

1. android ActionBar 最左側圖標,如何設成不能點擊

ActionBar 最左側圖標設置不可點擊只需要以下步驟:

  1. 獲取ActinBar實例

    ActionBar actionBar = getActionBar();

  2. 設置不可點擊

    actionBar.setDisplayHomeAsUpEnabled(true); // 決定左上角圖標的右側是否有向左的小箭頭。true有小箭頭,並且圖標可以點擊,false沒有小煎頭,並且不可點擊。

  3. actionBar.setDisplayShowHomeEnabled(false);//設置是否顯示HOME圖標,false表示沒有。

2. android actionbar和toolbar的區別

Action bar被包含在所有的使用Theme.Hole主題的Activity(或者是這些Activity的子類)中。

刪除actionbar

如果不想用ActionBar,那麼只要在theme主題後面" .NoActionBar", 就可以了。

由於現在用的不多了,所以就一帶而過了。

3. 怎麼設置android中actionbardrawertoggle的返回按鈕

private ActionBarDrawerToggle mDrawerToggle;
private DrawerLayout mDrawerLayout;
void init() {
// 添加菜單
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
//actionBar.setDisplayShowTitleEnabled(false);//去掉標題
actionBar.setDisplayUseLogoEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle(getResources().getString(R.string.app_title));
//actionBar.setLogo(R.drawable.icon_menu);

mDrawerLayout.setDrawerListener(new MyDrawerListener());//設置drawer的開關監聽
mDrawerToggle = new ActionBarDrawerToggle(activity, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close);
}
/** activity創建完成後 */
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();//該方法會自動和actionBar關聯, 將開關的圖片顯示在了action上,如果不設置,也可以有抽屜的效果,不過是默認的圖標
}

/** 菜單鍵點擊的事件處理 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
return mDrawerToggle.onOptionsItemSelected(item) || super.onOptionsItemSelected(item);
}
/** 設備配置改變時 */
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
}

/** drawer的監聽 */
private class MyDrawerListener implements DrawerLayout.DrawerListener {
@Override
public void onDrawerOpened(View drawerView) {// 打開drawer
mDrawerToggle.onDrawerOpened(drawerView);//開關狀態改為opened
}

@Override
public void onDrawerClosed(View drawerView) {// 關閉drawer
mDrawerToggle.onDrawerClosed(drawerView);//開關狀態改為closed
}

@Override
public void onDrawerSlide(View drawerView, float slideOffset) {// drawer滑動的回調
mDrawerToggle.onDrawerSlide(drawerView, slideOffset);
}

@Override
public void onDrawerStateChanged(int newState) {// drawer狀態改變的回調
mDrawerToggle.onDrawerStateChanged(newState);
}
}

4. android 怎樣獲取當前自己創建的actionbar

作為Android 3.0之後引入的新的對象,ActionBar可以說是一個方便快捷的導航神器。它可以作為活動的標題,突出活動的一些關鍵操作(如「搜索」、「創建」、「共享」等)、作為菜單的靈活使用,還可以實現類似TabWidget的標簽功能以及下拉導航的功能,系統能夠很好根據不同的屏幕配置來適應ActionBar的外觀,配合起Fragemtn可謂是十分強大。
那麼,對於今天的主角ActionBar怎麼去添加?在Android3.0默認主題HloleFraphic(全息)主題中,已經創造了ActionBar,所以只要targetSdkVersion的值不低於11,創建的Activity中默認都會帶有ActionBar。例如:

[html] view plain
<manifest ... >
<uses-sdk android:minSdkVersion="4"
android:targetSdkVersion="11" />
...
</manifest>
當然了,如果你不想為一個特定的Activity設置Action Bar,設置Activity主題為Theme.Holo.NoActionBar。
[html] view plain
<activity android:theme="@android:style/Theme.Holo.NoActionBar">

或者在運行時通過調用hide()隱藏Action Bar。自然也有show()。

[html] view plain
ActionBar actionBar = getActionBar();
actionBar.hide();

下面我們從下拉導航、視窗操作、標簽導航三個方面逐一討論ActionBar
第一,下拉導航
下拉導航最典型的應用場景就是在Google+中的使用,效果如下圖:

圖1;Google+ 圖2:本文示例

實現此效果分如下幾個步驟:
1.初始化一個SpinnerAdapter

[java] view plain
SpinnerAdapter mSpinnerAdapter = ArrayAdapter.createFromResource(this,
R.array.action_list,
android.R.layout.simple_spinner_dropdown_item);

2.生成一個OnNavigationListener來響應ActionBar的菜單項點擊操作

[java] view plain
/**
* 在這里配合Fragment,實現不同的頁面導航
*/
OnNavigationListener mOnNavigationListener = new OnNavigationListener() {

@Override
public boolean onNavigationItemSelected(int position, long itemId) {
Fragment newFragment = null;
switch (position) {
case 0:
newFragment = new Fragment1();
break;
case 1:
newFragment = new Fragment2();
break;
case 2:
newFragment = new Fragment3();
break;
default:
break;
}
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, newFragment, strings[position])
.commit();
return true;
}
};

3,將生成好的適配去和監聽器塞給ActionBar

[java] view plain
actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);//導航模式必須設為NAVIGATION_MODE_LIST
actionBar.setListNavigationCallbacks(mSpinnerAdapter,
mOnNavigationListener);

5. android中的actionbar怎麼設置左側圖標

ActionBar 最左側圖標設置不可點擊只需要以下步驟:
1獲取ActinBar實例
ActionBar actionBar = getActionBar();
2設置不可點擊
actionBar.setDisplayHomeAsUpEnabled(true); // 決定左上角圖標的右側是否有向左的小箭頭。true 有小箭頭,並且圖標可以點擊,false沒有小煎頭,並且不可點擊。
3actionBar.setDisplayShowHomeEnabled(false);//設置是否顯示HOME圖標,false表示沒有。

6. Android怎樣在Actionbar作出一個返回上一個activity按鈕

箭頭是
actionBar.setHomeButtonEnabled(true);
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
,點擊要在onOptionsItemselected裡面根據android.R.id.home重寫。
搜索框是optionsmenu中設置為SearchView

7. 如何調整Android ActionBar向上按鈕與屏幕左側的距離

可行的解決辦法是:
(1) 我想到的最直接的辦法是重新切一張圖,理由如下:
Google官網給出的「左向箭頭」的material icon,就包含上下左右間距:
(2) 看你的代碼,你已經為action bar提供了自定義的布局R.layout.my_booking_actionbar,為什麼不做的徹底一些呢?放棄使用android提供的Home鍵android.R.id.home作為UpIndicator。

而是在這個布局中添加一個ImageView,這樣就可以自定義你需要的間距離。然後實現ImageView.OnClickListener,點擊時返回父activity。
private void initActionBar() {
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
actionBar.setCustomView(R.layout.actionbar_crime_fragment);
View actionView = actionBar.getCustomView();

ImageView upButton = (ImageView) actionView.findViewById(R.id.actionBarUp);
upButton.setOnClickListener(new OnClickListener() {
@Override

8. 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);

9. 如何讓android的actionbar浮動且透明

在Android3.0之後,Google對UI導航設計上進行了一系列的改革,其中有一個非常好用的新功能就是引入的ActionBar,他用於取代3.0之前的標題欄,並提供更為豐富的導航效果。

一、添加ActionBar
1、不需要導入ActionBar,因為在android3.0或者以上版本中,ActionBar已經默認的包含在Activity中
2、在Android3.0的默認主題「holographic」中,已經創造了ActionBar
3、當android:minSdkVersion 或者 android:targetSdkVersion 屬性被設置成11或者更高時,應用會被認為是Android3.0版本(默認含有ActionBar)

二、隱藏ActionBar
1、我們可以通過把主題設置為Theme.Holo.NoActionBar為一個Activity去除掉ActionBar。 2、我們也可以通過在代碼中調用show()或者hide()方法來相應的顯示或者隱藏ActionBar
3、在我們使用actionBar.hide();方法是系統默認會將ActionBar佔用的空間分配給界面,此時顯示的界面將會重新繪制。
同樣調用actionBar.show();時也會重新繪制界面。如果我們一個程序需要頻繁的顯示或者隱藏ActionBar的話,這樣
就不會有良好的效果。Google提供給一個屬性可以讓ActionBar浮在界面上,當然你可以讓ActionBar的背景為透明,這樣會有良好的體驗效果。

10. Android怎麼動態更改actionbar的背景顏色

Android動態更改actionbar的背景顏步驟:

在backgroud下面再寫一個style,修改values-v14文件夾下的style.xml文件
[html] view plain
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<!--
Base application theme for API 14+. This theme completely replaces
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light">
<!-- API 14 theme customizations can go here. -->
<item name="android:actionBarStyle">@style/my_actionbar_style</item>
</style>

<style name="my_actionbar_style" parent="@android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#647b97</item>
<item name="android:titleTextStyle">@style/AcBar_titleStyle</item>
[html] view plain
<item name="android:backgroundStacked">#4A708B</item> <!-- 分離成tab時的tab顏色 -->
[html] view plain
<item name="android:backgroundSplit">@color/ab_backgroundSplit_color</item>
</style>
<style name="AcBar_titleStyle">

<item name="android:textColor">#FFFFFF</item>
</style>

</resources>

<item name="android:backgroundSplit">@color/ab_backgroundSplit_color</item> actionbar item
這樣就分離在底部時候的顏色。

熱點內容
百度雲如何解壓zip 發布:2024-04-25 14:38:57 瀏覽:570
母豬怎麼配置最好 發布:2024-04-25 14:35:47 瀏覽:75
php按鈕代碼 發布:2024-04-25 14:32:10 瀏覽:725
php數據類型轉換 發布:2024-04-25 14:15:17 瀏覽:750
windows調度演算法 發布:2024-04-25 14:14:28 瀏覽:456
下載喵星大作戰需要什麼配置 發布:2024-04-25 14:14:22 瀏覽:304
贛州伺服器數據存儲 發布:2024-04-25 14:13:41 瀏覽:889
控制演算法高手 發布:2024-04-25 13:57:10 瀏覽:472
文字游戲源碼php 發布:2024-04-25 13:57:08 瀏覽:881
安卓手機校準屏幕在哪裡 發布:2024-04-25 13:53:02 瀏覽:911