ActionBar showAsAction =“总是”不起作用

时间:2017-02-25 11:22:08

标签: android menu android-actionbar

我正在使用ActionBar和NavigationDrawer。我在ActionBar上添加了onCreateOptionMenu()。菜单项showAction =“always”但不起作用。

menu.xml文件

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:icon="@drawable/information"
        android:id="@+id/action_settings"
        android:orderInCategory="100"
        app:showAsAction="always"
        android:title="Bilgi"/>
</menu>

活动代码:

@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.infomenu, menu);
        return true;
    }

my_styles.xml:

<resources>

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
    -->
    <style name="AppBaseTheme" parent="android:Theme.Holo.Light">
    </style>

    <style name="AppTheme" parent="AppBaseTheme">
        <item name="android:actionBarStyle">@style/MyActionBar</item>
    </style>

    <style name="MyActionBar" parent="android:Widget.Holo.Light.ActionBar.Solid.Inverse">
        <item name="android:background">@color/background</item>
        <item name="android:titleTextStyle">@style/TitleColor</item>
    </style>

    <style name="TitleColor" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textColor">@color/white</item>
    </style>

</resources>

这是我的表现: 的manifest.xml

<application
        android:name=".util.AppController"
        android:allowBackup="true"
        android:icon="@drawable/eru"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" />
        <activity
            android:name=".Splash"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".login"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar.Fullscreen" />
        <activity
            android:name=".bildirimDetay"
            android:theme="@android:style/Theme.Holo.Light.NoActionBar" />

        <meta-data android:name="com.onesignal.NotificationOpened.DEFAULT" android:value="DISABLE" />
    </application>

帮助我。

2 个答案:

答案 0 :(得分:1)

在onCreateOptionsMenu()

中提及java代码
  @Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_main, menu);
    menu.clear();
    menu.add(Menu.FIRST, R.id.System_log, 4, "LOGOUT");

    String get_api_key = new Database_for_Api_key(Activity_Drawer_Dashboard.this).getApi_key();
        MenuItem item =
                menu.add(Menu.FIRST, R.id.dashboard_nodifycation, 3, "NOTIFICATION");
        item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    return true;
}

答案 1 :(得分:0)

从清单应用程序中删除主题,您就可以了:

替换:

<!-- select2 -->
<div @include('crud::inc.field_wrapper_attributes') >
    <label>{!! $field['label'] !!}</label>
    @include('crud::inc.field_translatable_icon')
    @if (isset($field['model']))
        <?php $entity_model = $crud->getModel();

        $pivot_entries = null;
        if (isset($entry)) {
            $pivot_entries = $entry->{$field['entity']}->keyBy(function ($item) {
                return $item->getKey();
            });
        }
        ?>
        <div class="row">
            <div class="col-sm-12">
                <table id="crudTable" class="table table-bordered table-striped display">
                    <thead>
                    <tr>
                        @if ($crud->details_row)
                            <th></th> <!-- expand/minimize button column -->
                        @endif

                        {{-- Table columns --}}
                        <th>Seleziona</th>
                        @foreach($field['pivotFields'] as $pivot_chunk)
                            <th>{{$pivot_chunk}}</th>
                        @endforeach

                    </tr>
                    </thead>
                    <tbody>
                    @foreach ($field['model']::all() as $connected_entity_entry) 
                    <tr>
                        <th scope="row">
                            <div class="col-sm-4">
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox"
                                               name="{{ $field['name'] }}[]"
                                               value="{{ $connected_entity_entry->id }}"

                                               @if( ( old( $field["name"] ) && in_array($connected_entity_entry->id, old( $field["name"])) ) || (isset($field['value']) && in_array($connected_entity_entry->id, $field['value']->pluck('id', 'id')->toArray())))
                                               checked="checked"
                                                @endif > {!! $connected_entity_entry->{$field['attribute']} !!}
                                    </label>
                                </div>
                            </div>
                        </th>
                        <td>
                            @foreach(array_chunk($field['pivotFields'], 2, true) as $pivot_chunk)
                                @foreach ($pivot_chunk as $pivot_field => $pivot_name)
                                    <?php
                                    $pivot_attr = null;
                                    if ($pivot_entries) {
                                        if ($pivot_entries->has($connected_entity_entry->getKey())) {
                                            $pivot      = $pivot_entries->get($connected_entity_entry->getKey())->pivot;
                                            $pivot_attr = $pivot->getAttribute($pivot_field);
                                        }
                                    }
                                    ?>
                                    <input type="number"
                                           name="{!! $pivot_field !!}[{{ $connected_entity_entry->getKey() }}]"
                                           value="{{ $pivot_attr }}" @include('crud::inc.field_attributes') />
                                @endforeach
                            @endforeach
                        </td>
                    </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
            @endif
            {{-- HINT --}}
            @if (isset($field['hint']))
                <p class="help-block">{!! $field['hint'] !!}</p>
            @endif
        </div>
</div>

使用:

<application
        android:name=".util.AppController"
        android:allowBackup="true"
        android:icon="@drawable/eru"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

将AppBaseTheme设为parent =“Theme.AppCompat.Light.DarkActionBar”

希望这能解决问题。