2013年12月15日 星期日

android - actionBar中的Overflow Menu(海苔條)出現的時機

參考:Adapting Android 4.0 to Older Hardware and Apps

http://developer.android.com/design/patterns/actionbar.html


發現有時候Overflow Menu(海苔條)會出現有時候又不會出現,後來看了上方參考的官方文件終於懂了:

首先解釋一下,Action OverFlow也就是俗稱的『海苔條』就是這個東西:
也就是上圖編號『4』最右邊的那個三個垂直排列點的按鈕啦~

依照官方文件說明,當裝置擁有『實體menuKey』時,那麼這條就不會出現,而要出現menu選單就是在手機上按下『實體menuKey』;當裝置沒有『實體menuKey』時,ActionBar的最右方(如上圖),就會出現Overflow Menu(海苔條),替代『實體menuKey』



以下是官方說明截取:

Phones with physical navigation keys

Android phones with traditional navigation hardware keys don't display the virtual navigation bar at the bottom of the screen. Instead, the action overflow is available from the menu hardware key. The resulting actions popup has the same style as in the previous example, but is displayed at the bottom of the screen.
我拿手邊的三個裝置試驗,試驗的app為『play商店』,『gmail』的確平板沒有『menuKey』的狀況下就會出現Overflow Menu(海苔條),反之另外兩隻手機因為有『menuKey』所以就沒顯示了 google查詢actionbar overflow force還有不少討論,看來有不少人都需要這種需求呢。
以這篇文章來說似乎不推薦強制去變更這個規則讓Overflow Menu(海苔條)一定要出現,畢竟這違反了android的設計想法(不過我就是有遇到客戶希望能出現,後來被我說這個是android的規範給打退想法的<其實是因為我不知道要如何讓她強制出現啦...汗,臺北等公車就有實現這個做法,不過我還沒成功就是...)

android - 使用ActionBar時啟動出現 java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity...

參考:ActionBarCompat: java.lang.IllegalStateException: You need to use a Theme.AppCompat

使用ActionBar如下:


public class MainActivity extends ActionBarActivity 
...

啟動時出現以下錯誤:

12-15 17:27:09.154: E/AndroidRuntime(422): FATAL EXCEPTION: main
12-15 17:27:09.154: E/AndroidRuntime(422): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidtest/com.example.androidtest.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
12-15 17:27:09.154: E/AndroidRuntime(422): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-15 17:27:09.154: E/AndroidRuntime(422): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)

解決方式:
將res/values/styles.xml下的parent屬性改為Theme.AppCompat的其中之一,例如:
"@style/Theme.AppCompat.Light"

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">
...