SCENARIO
我的应用程序是来自活动C的开放第三方应用程序(A-> B-> C)。之后,第三方应用程序完成后返回我在活动C上的应用程序。一切正常,直到活动C中只有一个EditText用软键盘输入,我想关闭它。
软键盘冻结但未关闭,我的应用程序也没有冻结。
以下是我的Sample XML(重现此错误)
ACTIVITY 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>
ACTIVITY 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>
ACTIVITY 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>
这是我的样本CLASS(A-&gt; B-&gt; 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>
答案 0 :(得分:0)
在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;
}