(Android Studio) Пользовательский макет панели действий не заполняет всю панель действий

перед setContentView()

LayoutInflater inflater = (LayoutInflater) getSupportActionBar() .getThemedContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View customActionBarView = inflater.inflate(R.layout.ab, null);
android.support.v7.app.ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM,  ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setCustomView(customActionBarView,    new android.support.v7.app.ActionBar.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT,  ViewGroup.LayoutParams.MATCH_PARENT));

в ab.xml image1

в моем приложении

image2

интервал стилей.xml

<!-- Base application theme. -->

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

</style>
<style name="ATheme" parent="AppBaseTheme">
    <item name="android:actionBarStyle">@style/AppTheme.ActionBar.a</item>
    <item name="actionBarStyle">@style/AppTheme.ActionBar.a</item>>
    <item name="android:icon">@android:color/transparent</item>
</style>
<style name="AppTheme.ActionBar.a" parent="Widget.AppCompat.Light.ActionBar">
    <item name="android:height">50dp</item>
    <item name="android:background">#d1d1d1</item>
</style>

in my Application, isn't filling action bar completely


person Taha Körkem    schedule 06.04.2015    source источник
comment
Быстрый вопрос; Какие значения для этого действия у атрибутов android:icon и android:logo в файле манифеста?   -  person Jayesh Elamgodil    schedule 06.04.2015
comment
@Jayesh Elamgodil я обновил с помощью styles.xml   -  person Taha Körkem    schedule 06.04.2015
comment
Не могли бы вы попробовать добавить запись android:logo с тем же значением цвета/прозрачности в ваш файл styles.xml?   -  person Jayesh Elamgodil    schedule 06.04.2015
comment
Извините, что это не сработало. Я не совсем уверен, но у меня есть сомнения относительно ViewGroup.LayoutParams.MATCH_PARENT? не могли бы вы попробовать FILL_PARENT   -  person Jayesh Elamgodil    schedule 06.04.2015
comment
я попробовал FILL_PARENT, но ничего не изменилось   -  person Taha Körkem    schedule 06.04.2015
comment
Пожалуйста, обратите внимание на модификации.   -  person Ibrahim Disouki    schedule 06.04.2015
comment
хорошо, спасибо за ваши коды   -  person Taha Körkem    schedule 06.04.2015


Ответы (1)


Ответ: Измени свой стиль вот так.

<resources>

    <!-- the theme applied to the application or activity -->
    <style name="AppTheme"
        parent="Theme.AppCompat.Light.DarkActionBar">

        <!-- Support library compatibility -->
        <item name="actionBarStyle">@style/MyActionBar</item>
    </style>

    <!-- ActionBar styles -->
    <style name="MyActionBar"
        parent="Widget.AppCompat.Toolbar">

        <!-- Support library compatibility -->
        <item name="contentInsetStart">0dp</item>
        <!--<item name="background">@android:color/transparent</item>-->
    </style>

</resources>

И ваш макет ActionBar.xml выглядит следующим образом: Примечание: если вы изменили 'android:layout_height="?attr/actionBarSize"' на 'android:layout_height="match_parent"', он не заполнит всю ширину панели действий, и если вы изменен LinearLayout на RelativeLayout с 'android:layout_height="match_parent"' Панель действий будет заполнять весь экран

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:gravity="center"
    android:background="#0000FF"
    android:layout_height="?attr/actionBarSize">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:textColor="#FFFFFF"
        android:text="Aplication"
        />

</LinearLayout>

Окончательно :

setContentView(R.layout.activity_main);

        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayOptions( ActionBar.DISPLAY_SHOW_CUSTOM);
        actionBar.setCustomView(R.layout.ab);

        View customActionBarView = actionBar.getCustomView();

Надеюсь, это поможет.

person Ibrahim Disouki    schedule 06.04.2015