編輯:關於Android編程
安裝ActionBar:
Support Android 3.0 and Above Only(僅支持3.0版本之後)
Support Android 2.1 and Above(如果想讓應用支持3.1版本之後,需如下操作)...
1安裝v7 appcompat 庫
2Update your activity so that it extends ActionBarActivity. For example:public class MainActivity extends ActionBarActivity { ... }3In your manifest file, update either the element or individual elements to use one of the Theme.AppCompat themes. For example:
1.Specify the Actions in XML
3.0以上版本:
2.0以上版本:
2.Add the Actions to the Action Bar:使ActionBar生效
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu items for use in the action bar MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_activity_actions, menu); return super.onCreateOptionsMenu(menu); }
3.Respond to Action Buttons相應ActionBar的事件
@Override public boolean onOptionsItemSelected(MenuItem item) { // Handle presses on the action bar items switch (item.getItemId()) { case R.id.action_search: openSearch(); return true; case R.id.action_settings: openSettings(); return true; default: return super.onOptionsItemSelected(item); } }Add Up Button for Low-level Activities:增加返回至上一個Activity的動作按鈕:
1.不管是4.0以上版本還是使用ActionBarActivity從支持庫都需要:
增加android:parentActivityName屬性
... ...
調用setDisplayHomeAsUpEnabled():
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_displaymessage); getSupportActionBar().setDisplayHomeAsUpEnabled(true); // If your minSdkVersion is 11 or higher, instead use: // getActionBar().setDisplayHomeAsUpEnabled(true); }
因為設置了android:parentActivityName屬性,所以系統知道要返回的父Activity,所以不用設置事件監聽
Use an Android Theme(當使用支持庫的時候分別為如下,對應括號中為非支持庫的)
When using the Support Library, you must instead use the Theme.AppCompat themes:
Theme.AppCompat for the "dark" theme. (Theme.Holo)
Theme.AppCompat.Light for the "light" theme.(Theme.Holo.Light)
Theme.AppCompat.Light.DarkActionBar for the light theme with a dark action bar.(Theme.Holo.Light.DarkActionBar)
Customize the Background(改變ActionBar的背景)
For Android 3.0 and higher only:
1.定義資源文件:res/values/themes.xml
2.Then apply your theme to your entire app or individual activities(引用資源文件):
For Android 2.1 and higher: 1.res/values/themes.xml:
2.Then apply your theme to your entire app or individual activities:
Customize the Text Color(自定義ActionBar字體顏色)
For Android 3.0 and higher only:res/values/themes.xml:
For Android 2.1 and higher(When using the Support Library, your style XML file might look like this:):res/values/themes.xml
Customize the Tab Indicator(自定義選項卡TabHost的樣式,使用選擇器)
res/drawable/actionbar_tab_indicator.xml:
然後:
For Android 3.0 and higher only:res/values/themes.xml:
For Android 2.1 and higher:res/values/themes.xml:
Overlaying the Action Bar(自動隱藏ActionBar):
Enable Overlay Mode(自動隱藏模式):For Android 3.0 and higher only:
Then apply your theme to your entire app or individual activities:For Android 2.1 and higher:
Then apply your theme to your entire app or individual activities:
Specify Layout Top-margin(top留空白,避免與ActionBar接觸):
沒有使用支持庫:
... 使用了支持庫:
...
TextPaint是paint的子類,用它可以很方便的進行文字的繪制,一般情況下遇到繪制文字的需求時,我們一般用TextPaint所提供的方法。開始學習如何繪制文字之前,
一.效果展示在Android手機的桌面上,我們經常可以看到如下小控件在這些控件上,可以顯示我們APP的一些重要的交互信息,以我最近開發的手機衛士為例,在widget上可以
本文實例講述了Android編程布局控件之AbsoluteLayout用法。分享給大家供大家參考,具體如下:AbsoluteLayout是絕對布局管理器,指的是指定組件的
Volley現在已經被官方放到AOSP裡面,已經逐步成為Android官方推薦的網絡框架。類抽象對Http協議的抽象Requeset顧名思義,對請求的封裝,實現了Comp