build.gradleで指定するtargetSdkが変わるとテーマが切り替わったり、バーチャルメニューキーが表示されたりします。
Android 4.4端末で5.1のAPIレベルを指定すると以下のように今風のUIが表示されています
しかし、Android 4.4端末で2.2のAPIレベルを指定すると以下のようにバーチャルのメニューキーが表示され、また古いUIが表示されます。また上はActionBarではなく、細いバーが表示されています。
そこで、仕組みがわからなくてもやもやしていました。
targetSdkVersionの仕組みがわからなくてもやもや、、 いったいどんな仕組みでメニューボタンが現れたり消えたり、テーマが古いのになったりするのか、、
— takahirom (@new_runnable) 2015, 8月 12
targetSdkVersionによって切り替える仕組みなどがあるわけではなく、
targetSdkVersionは普通にAndroidの中のプログラムで利用するためのもののようです。。
ちょっと探してみたのは以下になります(違う場所を見ているなどがありましたらコメントお願いします。)
メニューキーの切り替わるのはなぜ?
        final Context context = getContext();
        final int targetSdk = context.getApplicationInfo().targetSdkVersion;
        final boolean targetPreHoneycomb = targetSdk < android.os.Build.VERSION_CODES.HONEYCOMB;
        if (targetPreHoneycomb || (targetPreIcs && targetHcNeedsOptions && noActionBar)) {
            setNeedsMenuKey(WindowManager.LayoutParams.NEEDS_MENU_SET_TRUE);
        } else {
            setNeedsMenuKey(WindowManager.LayoutParams.NEEDS_MENU_SET_FALSE);
        }
テーマが変わるのはなぜ?
   @Override public Resources.Theme getTheme() {
        if (mTheme != null) {
            return mTheme;
        }
        mThemeResource = Resources.selectDefaultTheme(mThemeResource,
                getApplicationInfo().targetSdkVersion);
        initializeTheme();
        return mTheme;
    }
ActionBarの高さが違うのはなぜ?
    public boolean hasEmbeddedTabs() {
        final int targetSdk = mContext.getApplicationInfo().targetSdkVersion;
        if (targetSdk >= Build.VERSION_CODES.JELLY_BEAN) {
            return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs);
        }
        // The embedded tabs policy changed in Jellybean; give older apps the old policy
        // so they get what they expect.
        return mContext.getResources().getBoolean(R.bool.action_bar_embed_tabs_pre_jb);
    }
    public int getTabContainerHeight() {
        TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar,
                com.android.internal.R.attr.actionBarStyle, 0);
        int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0);
        Resources r = mContext.getResources();
        if (!hasEmbeddedTabs()) {
            // Stacked tabs; limit the height
            height = Math.min(height,
                    r.getDimensionPixelSize(R.dimen.action_bar_stacked_max_height));
        }
        a.recycle();
        return height;
    }


