簡體   English   中英

關閉時,軟鍵盤不會關閉並凍結

[英]soft keyboard doesn't close and freeze when close

情景

我的應用程序是活動C(A-> B-> C)的第三方應用程序。 之后,第三方應用程序完成后返回我在活動C上的應用程序。一切正常,直到活動C中只有一個EditText用軟鍵盤輸入,我想關閉它。

軟鍵盤凍結而不是關閉,我的應用程序也沒有凍結。

  • 我的測試設備基於Android KitKat。
  • 我更改為其他鍵盤默認和自定義..沒有希望
  • 我按下主頁按鈕並再次返回我的應用軟鍵盤行為。

這是我的Sample XML(重現這個bug)

活動A.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
        >
    <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Go to Activity B"
            android:id="@+id/btnNext"/>
</LinearLayout>

活動B.

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

    <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Go To Activity C"
            android:id="@+id/btnNext"/>
</LinearLayout>

活動C.

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbarStyle="outsideOverlay">



            <LinearLayout
                    android:orientation="vertical"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_margin="@dimen/padding_medium"
                    android:background="#DEE1E3"
                    android:id="@+id/llReceiverContainer">


                <LinearLayout
                        android:orientation="horizontal"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content">

                    <EditText
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_margin="@dimen/padding_default"
                            android:hint="Receiver Name"
                            android:id="@+id/edtReceiver"/>
                </LinearLayout>

                <Button
                        android:layout_width="match_parent"
                        android:layout_height="@dimen/button_height_big"
                        android:layout_marginBottom="@dimen/padding_default"
                        android:layout_marginLeft="@dimen/padding_default"
                        android:layout_marginRight="@dimen/padding_default"
                        android:text="Ex. Call 3rd Party App"
                        android:textColor="#fff"
                        android:textStyle="bold"
                        android:textSize="@dimen/font_large"
                        android:id="@+id/btnTestMpos"/>

            </LinearLayout>

</ScrollView>

這是我的Sample CLASS(A-> B-> C只調用startActivity)

CLASS ActivityC

public class ActivityC extends Activity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_c);

        Button btnTestMpos = (Button) findViewById(R.id.btnTestMpos);
        EditText edtUser = (EditText) findViewById(R.id.edtReceiver);
        btnTestMpos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                payWithMPOS();
            }
        });
    }

    private void payWithMPOS() {
        //call thire pparty application
    }

    // return from 3rd party application
    protected void onNewIntent(Intent intent) {
        setIntent(intent);
        getResultFromMPOS();
    }

    public void getResultFromMPOS() {
        // extract result from 3rd party applicaiton
    }
}

表現

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.ui.keyboard"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk android:minSdkVersion="14"/>
    <uses-permission android:name="android.permission.GET_TASKS" >
    </uses-permission>


    <application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
        <activity android:name=".ActivityA"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".ActivityB"
                  android:label="@string/app_name">
        </activity>
        <activity android:name=".ActivityC"
                  android:launchMode="singleTask"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="com.example.mpos.integration" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>
</manifest>

在你的Activity C Java類中試試這個

ScrollView yourScrollViewName= (Button) findViewById(R.id.yourScrollViewId);
yourScrollViewName.setOnTouchListener(this);

@Override
    public boolean onTouch(View v, MotionEvent event) {
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0);
        return false;

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM