【问题标题】:Android Input Method Editor Works in Landscape but not PortraitAndroid 输入法编辑器可以横向工作,但不能纵向工作
【发布时间】:2016-05-23 22:03:54
【问题描述】:

屏幕顶部的背景使用以下主题,并且应该是透明的。在纵向模式下,背景变为黑色。有时这甚至不会发生,背景保持透明。为了测试这一点,我正在使用 TED 文本编辑器应用程序。正如我所说,在 TED 中,纵向模式下背景会变黑。我编写了自己的活动,该活动具有多行文本输入字段,并且在此活动中,背景正确显示。在另一个示例中,当我尝试撰写新电子邮件时,Gmail 应用中的背景在纵向模式下变为白色。

我也在下面展示了一些 IME 的布局。

    <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>

这是 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>

【问题讨论】:

    标签: android android-theme android-input-method


    【解决方案1】:

    所以如果我使用布局来填充屏幕,然后使用权重将布局一分为二,然后使布局的上半部分透明,那是行不通的,因为当您单击透明区域时,那就是仍在布局内,样式规则按“windowCloseOnTouchOutside”表示。我必须做的是设置一个覆盖整个屏幕的布局,然后以编程方式测量整个屏幕并重新将布局的大小设置为屏幕大小的一半(再次以编程方式)并设置重力到底部。下面是测量屏幕大小的代码,下面是调整布局大小的代码。

        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;
    

    调整布局大小。就我而言,我需要自己为布局充气。

        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);
    

    我希望这对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多