Example usage for android.app Activity requestWindowFeature

List of usage examples for android.app Activity requestWindowFeature

Introduction

In this page you can find the example usage for android.app Activity requestWindowFeature.

Prototype

public final boolean requestWindowFeature(int featureId) 

Source Link

Document

Enable extended window features.

Usage

From source file:Main.java

public static void showAsPopup(Activity activity) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        return;/* www . ja v  a2 s  .  com*/
    }
    activity.requestWindowFeature(Window.FEATURE_ACTION_BAR);

    //To show activity as dialog and dim the background, you need to declare android:theme="@style/PopupTheme" on for the chosen activity on the manifest
    Window window = activity.getWindow();
    window.setFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND, WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    Display display = activity.getWindowManager().getDefaultDisplay();
    WindowManager.LayoutParams params = window.getAttributes();
    params.height = (int) (display.getHeight() * 0.95);
    params.width = Math.min((int) (display.getWidth() * 0.9), (int) (params.height * 0.85));
    params.gravity = Gravity.BOTTOM;
    params.alpha = 1.0f;
    params.dimAmount = 0.5f;
    window.setAttributes(params);
}

From source file:menion.android.whereyougo.gui.extension.activity.CustomActivity.java

protected static boolean setScreenBasic(Activity activity) {
    try {/* www  .  j a  va2  s  .c  om*/
        activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
        return true;
    } catch (Exception e) {
        // TODO Logger.e(TAG, "setFullScreen(" + activity + ")", e);
    }
    return false;
}

From source file:com.gosuncn.core.util.view.StatusBarUtils.java

/**
 * ????/*  www . j a va 2s .co  m*/
 * <p>??setContentView??</p>
 * <p>Activity?AppCompatActivity</p>
 * <p>??????QQ?</p>
 * <p>?Activityandroid:theme="@android:style/Theme.NoTitleBar.Fullscreen"</p>
 * <p>?Activity?AppCompatActivity</p>
 *
 * @param activity activity
 */
public static void hideStatusBar(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

From source file:com.google.android.apps.mytracks.util.Api8Adapter.java

@Override
public void hideTitle(Activity activity) {
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
}

From source file:org.cryptsecure.Utility.java

/**
 * Sets the content view with custom title. This is necessary for a holo
 * layout where a custom title bar is normally not permitted.
 * /*  w  w  w  .  ja v  a  2  s  .  c o  m*/
 * @param activity
 *            the activity
 * @param resIdMainLayout
 *            the res id main layout
 * @param resIdTitle
 *            the res id title
 * @return the linear layout
 */
public static LinearLayout setContentViewWithCustomTitle(Activity activity, int resIdMainLayout,
        int resIdTitle) {
    Context context = activity.getApplicationContext();

    // Inflate the given layouts
    LayoutInflater inflaterInfo = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View titleView = (View) inflaterInfo.inflate(resIdTitle, null);
    View mainView = (View) inflaterInfo.inflate(resIdMainLayout, null);

    // Own custom title bar
    //
    // ATTENTION:
    // ADD THIS TO THEME <item name="android:windowNoTitle">true</item>
    activity.requestWindowFeature(Window.FEATURE_NO_TITLE);
    // We can ONLY disable the original title bar because you cannot combine
    // HOLO theme with a CUSTOM title bar :(
    // So we make our own title bar instead!

    // ALSO REMOVE TITLEBAR FROM APPLICATION AT STARTUP:
    // ADD TO MANIFEST
    // android:theme="@android:style/Theme.NoTitleBar"

    // THE FOLLOWING IS NOT WORKING WITH HOLO
    // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    // setContentView(R.layout.activity_main);
    // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
    // R.layout.title_main);

    // Create title layout
    LinearLayout.LayoutParams lpTitle = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    LinearLayout titleLayout = new LinearLayout(context);
    titleLayout.setOrientation(LinearLayout.VERTICAL);
    titleLayout.addView(titleView);
    titleLayout.setLayoutParams(lpTitle);

    // Create main layout
    LinearLayout.LayoutParams lpMain = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    LinearLayout mainLayout = new LinearLayout(context);
    mainLayout.setOrientation(LinearLayout.VERTICAL);
    mainLayout.addView(mainView);
    mainLayout.setLayoutParams(lpMain);

    // Create root outer layout
    LinearLayout outerLayout = new LinearLayout(context);
    outerLayout.setOrientation(LinearLayout.VERTICAL);
    outerLayout.addView(titleLayout);
    outerLayout.addView(mainLayout);

    // outerLayout.setBackgroundColor(Color.rgb(255, 0, 0));
    // mainLayout.setBackgroundColor(Color.rgb(0, 255, 0));
    // titleLayout.setBackgroundColor(Color.rgb(0, 0, 255));

    // lpSectionInnerLeft.setMargins(20, 5, 0, 15);
    // LinearLayout.LayoutParams lpSectionInnerRight = new
    // LinearLayout.LayoutParams(
    // 90, LinearLayout.LayoutParams.WRAP_CONTENT, 0f);
    // lpSectionInnerRight.setMargins(0, 5, 15, 15);

    // After setting NO TITLE .. apply the layout
    activity.setContentView(outerLayout);

    return mainLayout;
}