您好,登錄后才能下訂單哦!
對于ActionBar,谷歌文檔介紹了2種寫法,其中2.1是帶v7包。
對于3.0(使用系統自帶的主題) ---帶應用的icon
If you've created a custom theme, be sure it uses one
of the Theme.Holo
themes
as its parent.
android:theme="@android:style/Theme.Holo"
對于2.1帶v7包(使用v7包里的主題) ---不帶應用的icon
第1:Activity要繼承自ActionBarActivity
第2:Activity的主題必須是AppCompat
<activity android:theme="@style/Theme.AppCompat.Light" ... >
public class MainActivity extends ActionBarActivity { ... }
千萬要注意的問題:AppCompatActivity必須與AppCompat的主題配合使用,不能混搭。
>>>>對于使用了支持庫的,有一個問題需要注意一下:
只有AppComatActivity才有showAsAction這個屬性,Activity只有菜單,并不會將菜單里的條目做
成Action。
If your app is using the Support Library for compatibility on versions
as low as Android 2.1, the showAsAction
attribute is not available from
the android:
namespace. Instead this attribute is provided by the Support Library
and you must define your own XML namespace and use that namespace as the attribute prefix.
(A custom XML namespace should be based on your app name, but it can be any
name you want and is only accessible within the scope of the file in which you declare it.)
For example:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:yourapp="http://schemas.android.com/apk/res-auto" >
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"
android:icon="@drawable/ic_action_search"
android:title="@string/action_search"
yourapp:showAsAction="ifRoom" />
...
</menu>
>>>>為Activity增加返回按鈕:
方式1:隱式的進行綁定
先配置Activity,包括它的父Activity(也就是它返回跳轉到的那個Activity)
<!-- A child of the main activity -->
<activity
android:name=".Activity2"
android:label="@string/title_activity_display_message"
android:parentActivityName=".MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
然后
(Bundle savedInstanceState) { .onCreate(savedInstanceState)setContentView(R.layout.)getSupportActionBar().setDisplayHomeAsUpEnabled()}
》》Styling the Action Bar(做出有風格的ActionBar)
1.Use an Android Theme
###不使用支持庫的情況
Theme.Holo
for a "dark" theme. 工具欄和主面板都是黑色主題(API11)
Theme.Holo.Light
for a "light" theme. 工具欄和主面板都是白色主題 (API11)
Theme.Holo.Light.DarkActionBar 工具欄為黑色,主面板為白色(API14
When using the Support Library, you must instead use theTheme.AppCompat
themes:
Theme.AppCompat
for the
"dark" theme.
Theme.AppCompat.Light
for the "light" theme.
Theme.AppCompat.Light.DarkActionBar
for the light theme with a dark action bar
2.Customize the Background
3.Customize the Text Color
4.Customize the Tab Indicator
上面的我也沒有寫,具體請看谷歌文檔Develop-Training-Adding Action Bar-Styling the ActionBar
>>Overlaying the Action Bar(使ActionBar堆疊在主面板之上)
這樣做的好處:一旦ActionBar hide或者show的時候,不會引起主界面的重繪,效率高。
需要考慮的一個問題:主面板要設置個margin,不讓ActionBar遮蓋住主界面。
android:paddingTop="?android:attr/actionBarSize"
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。