简体   繁体   中英

disable soft keyboard on android not working. for testing

I've tried muliple ways to disable the softkeyboard from my test but isn't working.

  1. added to my androidmanifest.xml

      <activity android:name="com.photos.ui.activity.WelcomeActivity" android:windowSoftInputMode="stateHidden" /> 

    The activity is the name of the folders for the app (not my test script)

  2. added to my androidmanifest.xml

     <LinearLayout android:focusable="true" android:focusableInTouchMode="true" 

    />

  3. placed this in my test and in my setup

     EditText edtView=solo.getEditText(0); edtView.setInputType(InputType.TYPE_NULL); 
  4. tried

      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(solo.getEditText(0).getWindowToken(),0); 

but getSystemService is giving me an error. (undefined in my class) I'm not sure how to use these two commands

and I'm using 2.3 with a samsung exhibit II.

right now I'm using:

    hnm, what calls would I need to create the context object? right now im using:    private Context context;

private static Class<?> launcherActivityClass;
static{
        try {
                launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
        }
}

public TestMain() throws ClassNotFoundException {
    super(TARGET_PACKAGE_ID, launcherActivityClass);
}

public TestMain(String name) throws ClassNotFoundException {
    super(TARGET_PACKAGE_ID, launcherActivityClass);
    setName(name);
}

public TestMain(String name, Class<?> className) throws ClassNotFoundException {
    super(TARGET_PACKAGE_ID, className);
    setName(name);

}


private Solo solo;

 @Override  
protected void setUp() throws Exception {


        solo = new Solo(getInstrumentation(), getActivity());

    Log.v("setup","setup");



}

@Override
protected void tearDown() throws Exception {

        solo.finishOpenedActivities();
}   

Thanks.

getSystemService() is a method of Context so if the class that you are inside of when you are trying to call that is not a Context (Activity extends, and thus is a Context) then you'll need to put a reference and a dot in front of the method. How you need to do that depends on what type of structure you are trying to put those two lines into. If you are still inside an Activity, but are currently in an inner class you can fix it by doing like this:

YourActivityName.this.getSystemService();

if you are inside some other class then you'll need to have a way to pass a Context in to it so that you can call the method on the Context object that is passed to you (ie as a constructor parameter).

Edit:

I think, You would want to be putting this code inside the WelcomeActivityI think, not inside of this test object. I can't tell based on what you've posted what you are trying to do all the way, but if you are deadset on doing it from that chunk of code my guess is that launcherActivityClass is going to be involved in obtaining the context. Are you inflating this into an Activity object? if so you can pass it through as a context without doing anything to it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM