Android examples for User Interface:SmartBar
Is compatible Device With SmartBar
/*/* www .j av a 2s . c om*/ * Copyright (C) 2013 Yrom Wang * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.lang.reflect.Field; import java.lang.reflect.Method; import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.content.pm.ActivityInfo; import android.os.Build; import android.support.v7.app.ActionBar; import android.view.ViewConfiguration; public class Main{ @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static void compatibleDeviceWithSB(Activity activity) { if (hasSB()) { activity.getWindow().setUiOptions( ActivityInfo.UIOPTION_SPLIT_ACTION_BAR_WHEN_NARROW); } } @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) public static boolean hasSB() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) return false; try { Method method = Build.class.getDeclaredMethod("hasSmartBar"); return ((Boolean) method.invoke(null)).booleanValue(); } catch (Exception e) { // ignore } return Build.DEVICE.equalsIgnoreCase("mx2") || Build.DEVICE.equalsIgnoreCase("mx3"); } }