0

The background for the top of the screen uses the following theme, and should be transparent. In portrait mode the background turns black. Sometimes this doesn't even happen and the background stays transparent. To test this out I'm using the TED text editor app. As I say the background turns black in portrait mode in TED. I wrote my own activity that has a multi-line text input field, and in this activity the background displays correctly. In another example the background in my Gmail app turns white in portrait mode when I try to compose a new email.

I show some of the layout of the IME below too.

    <resources>
        <!-- some styles here -->

        <style name="AppTheme.Custom"  parent="AppTheme.NoActionBar">
            <item name="android:windowActionBar">false</item>
            <item name="android:windowNoTitle">true</item>
            <item name="android:windowIsTranslucent" >false</item>
            <item name="android:windowIsFloating">true</item>
            <item name="android:windowCloseOnTouchOutside">true</item>
            <item name="android:colorBackgroundCacheHint">@android:color/transparent</item>
            <item name="android:backgroundDimEnabled">false</item>
            <item name="android:windowContentOverlay">@android:color/transparent</item>
            <item name="android:backgroundDimAmount">0.5</item>
        </style>
    </resources>

Here's some of the layout for the IME:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        >

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:weightSum="1"
            android:theme="@style/AppTheme">

            <LinearLayout
                android:background="#00000000"
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="0.5"
                android:theme="@style/AppTheme.Custom"
                android:layout_gravity="top"
                android:id="@+id/topHalf"></LinearLayout>

            <include layout="@layout/content_main"
                android:layout_weight="0.5"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:theme="@style/AppTheme"
                android:layout_gravity="bottom"
                />

        </LinearLayout>

    </FrameLayout>
D Liebman
  • 337
  • 1
  • 8
  • 17

1 Answers1

0

so if I use a layout to fill the screen, then devide the layout in two using weights, and then make the top half of the layout transparent, that won't work, because when you click in the transparent area, that's still inside the layout, and the style rule works as it says 'windowCloseOnTouchOutside'. What I had to do was to set up a single layout that covered the entire screen, then programmatically measure the entire screen and re set the size of the layout to half the screen size (again programmatically) and set the gravity to BOTTOM. Below is code for measuring the screen size, and below it code for resizing the layout.

    WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    DisplayMetrics metrics = new DisplayMetrics();
    display.getMetrics(metrics);
    val.mWindowHeight = metrics.heightPixels;
    val.mWindowWidth = metrics.widthPixels;

resize the layout. in my case I need to inflate the layout myself.

    inputView = (RelativeLayout) getLayoutInflater().inflate(R.layout.content_main, null);
    ...
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, val.mWindowHeight/2);
    lp.gravity = Gravity.BOTTOM ;
    lp.height = val.mWindowHeight/2;
    inputView.setLayoutParams(lp);

I hope this helps someone.

D Liebman
  • 337
  • 1
  • 8
  • 17