Подтвердить что ты не робот

Как разместить элементы ActionBar в главной панели ActionBar и нижней панели

enter image description here

Приложение Google+ имеет макет, в котором есть элементы панели действий в основной панели действий и в нижней части. В настоящее время я использую android:uiOptions="splitActionBarWhenNarrow" для размещения элементов в нижней панели. Как разместить предметы как сверху, так и снизу?

4b9b3361

Ответ 1

Надеюсь, что мой ответ не слишком поздно для вас.

  • Используйте android:uiOptions="splitActionBarWhenNarrow" (это добавляет материал в нижнюю панель).
  • Создайте новый макет, подобный приведенному ниже коду (этот макет будет обрабатывать все ваши элементы на верхней панели).

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right" >
    <Switch
        android:id="@+id/switch1"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"/>
    <ImageButton
        android:id="@+id/action_starred"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="?android:attr/actionButtonStyle"
        android:src="@android:drawable/ic_menu_compass" 
        android:onClick="FakeMenu"/>
    </LinearLayout>
    
  • Вставьте это в свою активность

    ActionBar actionBar = getActionBar();               
    actionBar.setCustomView(R.layout.actionbar_top); //load your layout
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_CUSTOM); //show it 
    
  • Что все:)

Ответ 2

Я не думаю, что это возможно с помощью стандартного ActionBar. При включении Splash ActionBar в узком экране будут отображаться действия ALL.

Нижняя панель приложения Google+ "создайте сообщение" Активность, похоже, является настраиваемой реализацией. Обратите внимание на то, что длинное нажатие означает, что ярлык действия не работает, а нижняя панель остается даже при переключении в альбомную ориентацию. Элемент location является тумблером, который также является нестандартным поведением ActionBar.

Ответ 3

У меня была такая же проблема, ничего, что я нашел, действительно работало, потому что мне приходилось иметь дело с узкой панелью действий, а затем на больших устройствах кнопки были размещены сверху, а не внизу. Поэтому я окончательно решил его, разместив "нижний колонтитул" в основном макете:

Bottom ActionBar Example

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="false"
        android:layout_above="@+id/footer">

        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:id="@+id/container"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="@dimen/body_padding_large"
            android:paddingRight="@dimen/body_padding_large"
            android:paddingTop="@dimen/body_padding_medium"
            android:paddingBottom="@dimen/body_padding_medium"
            android:gravity="top">

        </LinearLayout>

    </ScrollView>
    <LinearLayout android:id="@+id/footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentBottom="true"
        style="@android:style/ButtonBar">
        <Button android:id="@+id/btn_1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 1" />

        <Button android:id="@+id/btn_2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button 2" />
    </LinearLayout>
</RelativeLayout>

Ответ 4

Нижняя панель заполняется, когда у вас больше предметов, чем показано на верхней панели.

Вместо того, чтобы показывать "переполненные" три точки, предметы будут помещены в нижнюю панель. Не забудьте использовать:

android:showAsAction="ifRoom|withText"

в ваших пунктах меню в XML.

Подробнее здесь: http://developer.android.com/guide/topics/ui/actionbar.html#SplitBar

Ответ 5

<?xml version="1.0" encoding="utf-8"?>

< LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="right" >

<Switch
    android:id="@+id/switch1"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"/>

<ImageButton
    android:id="@+id/action_starred"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="?android:attr/actionButtonStyle"
    android:src="@android:drawable/ic_menu_compass" 
    android:onClick="FakeMenu"/>

</LinearLayout>









//Then put these lines of code in your java class or activity

    ActionBar actionBar = getActionBar();               
    actionBar.setCustomView(R.layout.actionbar); //load your layout
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_SHOW_USTOM); //show it 

//надеюсь, что это поможет