這裏是我所拼湊起來的一個綜述:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dropdownContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/leftBuffer"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<LinearLayout
android:layout_width="150dp"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/actionbarDropdown"
style="@style/Widget.ActionBarDropDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:cacheColorHint="@android:color/transparent"
android:entries="@array/sortOptions" />
<LinearLayout
android:id="@+id/bottomBuffer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/rightBuffer"
android:layout_width="118px"
android:layout_height="match_parent" />
</LinearLayout>
添加一個onClick到動作條項,其中:增加了上述佈局作爲一個孩子到你的活動的ViewGroup根給你下降的幻覺。
將OnClick添加到從根ViewGroup中刪除視圖的每個緩衝區允許在嘗試移動焦點時下拉到「退出」。
的下拉是樣式信息:
<item name="android:background">@drawable/menu_dropdown_panel_holo_light</item>
<item name="android:dropDownSelector">@drawable/list_selector_background</item>
每個列表項的佈局是:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:textSize="17sp"
android:gravity="right|center_vertical"
style="?android:attr/dropDownItemStyle"
android:ellipsize="marquee"
android:id="@android:id/text1">
</TextView>
這不會給溢出一滴的功能完美複製下來,但它非常接近。如果有其他人知道以更綜合的方式重現此功能的方法,我非常感興趣!
<?xml version="1.0" encoding="utf-8"?>
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/action_starred"
android:layout_width="wrap_content"
android:layout_height="match_parent"
style="?android:attr/actionButtonStyle"
android:src="@drawable/ic_action_star" />
我再附上OnClickListener
它在onCreateOptionsMenu()
它只是增加了一個片段,它需要創造一個ListPopupWindow
和設置的護理:
How's style =「@ style/Widget.ActionBarDropDown」defined?我無法解決這種風格? – Henrik