Добрый день всем! Буду очень признателен за помощь в след. вопросе:
Как сделать это:
Не подумайте, я думал как это сделать, но вменяемого ничего не смог придумать, вот и прошу помощи. Самым логичным кажется сделать через getMenuInflater().inflate(...); и добавить свойство android:uiOptions="splitActionBarWhenNarrow" в манифесте, но как добиться именно того, что на картинке, ума не приложу.
Попутно еще один вопрос:
Мои кнопки не реагируют на добавление свойства padding. Т.е. реагируют - они становятся больше, но вся эта область (кнопка + поля) закрашивается бекграундовым цветом, а мне нужно, чтобы поля были полями, а не просто расширением кнопки. Кто-нибудь сталкивался с подобным?
кастомный вью в actionbar (custom view in actionbar)
-
intelcom2009
- Сообщения: 2
- Зарегистрирован: 09 янв 2014, 10:25
- Mikhail_dev
- Сообщения: 2386
- Зарегистрирован: 09 янв 2012, 14:45
- Откуда: Самара
Re: кастомный вью в actionbar (custom view in actionbar)
Знаю точно что rezak90 делал кастомный ActionBar, но он пока что в отпуске до 16 числа. Самому пока не приходилось кастомизировать.
Re: кастомный вью в actionbar (custom view in actionbar)
Если я правильно понял вопрос по ActionBar:
[syntax=java]LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View titleView = vi.inflate(R.layout.title, null);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM + ActionBar.DISPLAY_SHOW_HOME);
getSupportActionBar().setCustomView(titleView);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);[/syntax]
Если не используется Sherlock или support lib v7 то использовать getActionBar() вместо getSupportActionBar().
А по поводу кнопок: "xml в студию" =)
[syntax=java]LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View titleView = vi.inflate(R.layout.title, null);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM + ActionBar.DISPLAY_SHOW_HOME);
getSupportActionBar().setCustomView(titleView);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);[/syntax]
Если не используется Sherlock или support lib v7 то использовать getActionBar() вместо getSupportActionBar().
А по поводу кнопок: "xml в студию" =)
-
intelcom2009
- Сообщения: 2
- Зарегистрирован: 09 янв 2014, 10:25
Re: кастомный вью в actionbar (custom view in actionbar)
ОК, Попробовал сделать так, как вы сказали, вот, что получилось: Тут также показаны те самые кнопки.klblk писал(а):Если я правильно понял вопрос по ActionBar:
[syntax=java]LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View titleView = vi.inflate(R.layout.title, null);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM + ActionBar.DISPLAY_SHOW_HOME);
getSupportActionBar().setCustomView(titleView);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);[/syntax]
Если не используется Sherlock или support lib v7 то использовать getActionBar() вместо getSupportActionBar().
А по поводу кнопок: "xml в студию" =)
Код OncreateOptionsMenu:
Код: Выделить всё
getMenuInflater().inflate(R.menu.menu_btnback_btnforward, menu);
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View titleView = vi.inflate(R.layout.menu_progressbar, null);
getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getActionBar().setCustomView(titleView);
Код menu_progressbar:
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="fill_horizontal"
android:focusable="false" >
<TextView
android:id="@+id/action_bar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="title bla bla"
android:padding="5dp"/>
<RadioGroup
android:layout_below="@id/action_bar_title"
android:id="@+id/rbgroup_menu_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="4dp">
<RadioButton
android:id="@+id/rb_menu_progressbar_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"
android:checked="true"/>
<RadioButton
android:id="@+id/rb_menu_progressbar_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"/>
<RadioButton
android:id="@+id/rb_menu_progressbar_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"/>
<RadioButton
android:id="@+id/rb_menu_progressbar_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"/>
<RadioButton
android:id="@+id/rb_menu_progressbar_5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false"
android:clickable="false"/>
</RadioGroup>
</RelativeLayout>
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/btn_menu_back"
android:showAsAction="always|withText"
android:title="@string/btn_menu_back_text"
android:icon="@drawable/ic_menu_back">
</item>
<item
android:id="@+id/btn_menu_forward"
android:showAsAction="always|withText"
android:title="@string/btn_menu_forward_text"
android:icon="@drawable/ic_menu_forward">
</item>
</menu>
Код: Выделить всё
<style name="ButtonStyle" parent="AppThemeWithMargins">
<item name="android:padding">@dimen/default_padding</item>
</style>
Разметка кнопок:
Код: Выделить всё
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:id="@+id/btn_Buy"
android:text="@string/btn_BuyTitle"
android:layout_weight="1"
android:background="@color/color_btnBuy_Background"
style="@style/ButtonStyle">
</Button>
<Button
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_gravity="center"
android:id="@+id/btn_Sell"
android:text="@string/btn_SellTitle"
android:background="@color/color_btnSell_Background"
android:layout_weight="1"
style="@style/ButtonStyle">
</Button>
</LinearLayout>
Буду рад любой помощи! Спасибо!
