MenuCompat.java revision ac5fe7c617c66850fff75a9fce9979c6e5674b0f
1/* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package androidx.core.view; 18 19import android.annotation.SuppressLint; 20import androidx.core.internal.view.SupportMenu; 21import androidx.core.os.BuildCompat; 22import android.view.Menu; 23import android.view.MenuItem; 24 25/** 26 * Helper for accessing features in {@link android.view.Menu}. 27 */ 28public final class MenuCompat { 29 /** 30 * Call {@link MenuItem#setShowAsAction(int) MenuItem.setShowAsAction()}. 31 * 32 * @deprecated Use {@link MenuItem#setShowAsAction(int)} directly. 33 */ 34 @Deprecated 35 public static void setShowAsAction(MenuItem item, int actionEnum) { 36 item.setShowAsAction(actionEnum); 37 } 38 39 /** 40 * Enable or disable the group dividers. 41 * 42 * @param menu Menu to enable/disable dividers on. 43 * @param enabled True if enabled 44 */ 45 @SuppressLint("NewApi") 46 public static void setGroupDividerEnabled(Menu menu, boolean enabled) { 47 if (menu instanceof SupportMenu) { 48 ((SupportMenu) menu).setGroupDividerEnabled(enabled); 49 } else if (BuildCompat.isAtLeastP()) { 50 menu.setGroupDividerEnabled(enabled); 51 } 52 } 53 54 private MenuCompat() {} 55} 56