GVKun编程网logo

android – 如何在使用setTextIsSelectable禁用键盘后启用键盘(android 关闭键盘)

3

本文将分享android–如何在使用setTextIsSelectable禁用键盘后启用键盘的详细内容,并且还将对android关闭键盘进行详尽解释,此外,我们还将为大家带来关于AndroidExte

本文将分享android – 如何在使用setTextIsSelectable禁用键盘后启用键盘的详细内容,并且还将对android 关闭键盘进行详尽解释,此外,我们还将为大家带来关于Android Extend BaseExpandableListAdapter、Android SetText更改键盘类型、Android TextView settextcolor selected、android – (tablayout)当editText聚焦时,标签会越过键盘的相关知识,希望对你有所帮助。

本文目录一览:

android – 如何在使用setTextIsSelectable禁用键盘后启用键盘(android 关闭键盘)

android – 如何在使用setTextIsSelectable禁用键盘后启用键盘(android 关闭键盘)

我使用的是custom in-app keyboard,所以我需要禁用系统键盘.我可以这样做

editText.setShowSoftInputOnFocus(false);

适用于Android API 21.但要做到同样的事情到API 11,我正在做

editText.setTextIsSelectable(true);

有时我想在使用setTextIsSelectable禁用它后再次显示系统键盘.但我无法弄清楚如何.执行以下操作会显示系统键盘,但如果用户隐藏键盘然后再次单击EditText,则键盘仍然不会显示.

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);

我想我可以做editText.setonFocuschangelistener,然后手动显示或隐藏系统键盘,但我宁愿撤消setTextIsSelectable做的任何事情.以下也不起作用:

editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.setLongClickable(true);

我该怎么做?

Related question

解决方法:

简短的回答

执行以下操作将反转setTextIsSelectable(true)的效果,并允许键盘在EditText获得焦点时再次显示.

editText.setTextIsSelectable(false);
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.setLongClickable(true);
editText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
editText.setText(editText.getText(), TextView.BufferType.SPANNABLE);

说明

阻止键盘显示的是isTextSelectable()为true.你可以看到here(感谢@adneal).

setTextIsSelectable的源代码是

public void setTextIsSelectable(boolean selectable) {
    if (!selectable && mEditor == null) return; // false is default value with no edit data

    createEditorIfNeeded();
    if (mEditor.mTextIsSelectable == selectable) return;

    mEditor.mTextIsSelectable = selectable;
    setFocusableInTouchMode(selectable);
    setFocusable(selectable);
    setClickable(selectable);
    setLongClickable(selectable);

    // mInputType should already be EditorInfo.TYPE_NULL and mInput should be null

    setMovementMethod(selectable ? ArrowKeyMovementMethod.getInstance() : null);
    setText(mText, selectable ? BufferType.SPANNABLE : BufferType.norMAL);

    // Called by setText above, but safer in case of future code changes
    mEditor.prepareCursorControllers();
}

因此,上面简短答案部分中的代码首先使用setTextIsSelectable(false)将mTextIsSelectable设置为false,然后逐个撤消所有其他副作用.

Android Extend BaseExpandableListAdapter

Android Extend BaseExpandableListAdapter

我正在尝试扩展Baseexpandablelistadapter,但是当我查看列表并选择要扩展的元素之一时,列表的顺序就会反转.例如,如果我有一个包含4个元素的列表并选择第1个元素,则顺序(从上到下)现在为4,3,2,1,第4个元素(现在位于顶部)展开.如果我对第4个元素进行了扩展,则该顺序将恢复为1,2,3,4,而不包含扩展元素.

这是我的实现:

公共类SensorExpandableAdapter扩展Baseexpandablelistadapter {

    private static final int FILTER_POSITION = 0;
    private static final int FUNCTION_POSITION = 1;
    private static final int NUMBER_OF_CHILDREN = 2;
    ArrayList<SensorType> mParentGroups;
    private Context mContext;
    private LayoutInflater mInflater;

    public SensorExpandableAdapter(ArrayList<SensorType> parentGroup, Context context) {
        mParentGroups = parentGroup;
        mContext = context;
        mInflater = LayoutInflater.from(mContext);
    }
    @Override
    public Object getChild(int groupPosition, int childPosition) {
        // Todo Auto-generated method stub
        if(childPosition == FILTER_POSITION) return "filter";
        else return "function";
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return childPosition;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        if(convertView == null)
        {
            convertView = (RelativeLayout)mInflater.inflate(R.layout.sensor_row_list_item, parent, false);
            if(childPosition == FILTER_POSITION) {
                ((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setText("Add Filter");
            } else {
                ((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setText("Add Function"); 
                ((CheckBox)convertView.findViewById(R.id.chkTextAddFilter)).setEnabled(false);
            }
        }
        return convertView;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        // Todo Auto-generated method stub
        return NUMBER_OF_CHILDREN;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return mParentGroups.get(groupPosition);
    }

    @Override
    public int getGroupCount() {
        // Todo Auto-generated method stub
        return mParentGroups.size();
    }

    @Override
    public long getGroupId(int groupPosition) {
        // Todo Auto-generated method stub
        return groupPosition;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        if(convertView == null)
        {
            convertView = mInflater.inflate(android.R.layout.simple_expandable_list_item_1, parent, false);
            TextView tv = ((TextView)convertView.findViewById(android.R.id.text1));
            tv.setText(mParentGroups.get(groupPosition).toString());
        }
        return convertView;
    }

    @Override
    public boolean hasstableIds() {
        // Todo Auto-generated method stub
        return true;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {
        // Todo Auto-generated method stub
        return true;
    }
}

`

我只需要使用我自己的SensorType类的简单ArrayList.所有班级的孩子都是一样的,只有两个.

另外,我如何在每个组LongClickable中创建父级?我已经尝试使用此getExpandableListView().setonLongClickableListener()…在我的ExpandableListActivity中,并在父TextView上设置了它的OnLongClickableListener,但都不起作用.

任何这方面的任何帮助非常感谢!

解决方法:

public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        if(convertView == null)
        {

只需注释掉“如果”.这应该有所帮助.

Android SetText更改键盘类型

Android SetText更改键盘类型

我正在开发一个包含EditText的android应用程序.

我通过调用来控制在editText中写的内容

et.addTextChangedListener(new TextWatcher() {
    public void afterTextChanged(Editable s) {
        String message = et.getText().toString();
        if(s.toString().compareto(before)!=0){
            et.setText(message);
            et.setSelection(et.getText().length());
        }
    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        before = et.getText().toString();
        System.out.println("After");
    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        System.out.println("ON");
    }
});

在afterTextChanged函数中,我使用et.setText(“ some Text”);
问题是,更改文本后,键盘也发生了变化,例如,如果打开了符号键盘,而我使用了setText,它将自动更改为qwerty.

我怎么解决这个问题?

解决方法:

我找不到您问题的直接解决方案,但是您可以做一些事情来解决您的问题!使用位于编辑文本上的文本视图(例如,您可以使用RelativeLayout在编辑文本上设置文本视图),并将编辑文本字体颜色设置为白色(或编辑文本的背景颜色),以使用户看不到它是真实文本.希望此代码段对您有所帮助:
main.xml(以res / layout格式):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activityRoot"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
     >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <requestFocus />
    </EditText>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="MyTextView" />

</RelativeLayout>     

您观察到的文本更改的活动:

public class TestproGuardActivity extends Activity {

    EditText et;
    TextView tv1;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv1 = (TextView)findViewById(R.id.textView1);
        et = (EditText)findViewById(R.id.editText1);

        et.addTextChangedListener(new TextWatcher() {
            private String before = "hasan";
            public void afterTextChanged(Editable s) {
               String message = et.getText().toString();
               if(s.toString().compareto(before )!=0){
//               et.setText(message);
                   tv1.setText(message);
//               et.setSelection(et.getText().length());
               }
            }
            public void beforeTextChanged(CharSequence s, int start, int count, int after){

                before = et.getText().toString();

                System.out.println("After");   

            }
            public void onTextChanged(CharSequence s, int start, int before, int count)
            {
                System.out.println("ON");
            }
        });
    }


}

Android TextView settextcolor selected

Android TextView settextcolor selected

文件color_select_3aa5f0_333333

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:color="@color/color_3AA5F0" android:state_selected="true"/>
    <item android:color="@color/color_333333" android:state_selected="false"/>
    <item android:color="@color/color_333333" />
</selector>




<TextView
        android:id="@+id/tv_woman"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_46"
        android:text="女"
        android:gravity="center"
        android:textSize="@dimen/sp_16"
        android:textapp:layout_constraintTop_toBottomOf="@+id/tv_man"
        android:layout_marginTop="@dimen/dp_20"
        android:textColor="@color/color_select_3aa5f0_333333"
        android:background="@drawable/bg_select_f7f7f7_ffffff"
        />

注意 ,在res下新建color 文件夹,并且selector 里的selected  item必须要为第一个,不能讲最后一个item 放在第一位

android – (tablayout)当editText聚焦时,标签会越过键盘

android – (tablayout)当editText聚焦时,标签会越过键盘

我用ViewPager setUp tabLayout,它有5个片段.
tabLayout与 android:layout_gravity设置为bottom.第三个片段有editText,当聚焦时,我的标签来自键盘.

Tablayout without EditText

TabLayout with EditText

主要布局:

<?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/appBarLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

         <include
              android:id="@+id/t"
             layout="@layout/toolbar"/>


        </android.support.design.widget.AppBarLayout>

  <android.support.v4.view.ViewPager
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"/>

  <android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tab="http://schemas.android.com/tools"
    android:layout_gravity="bottom"
    app:tabGravity="fill"
    android:background="@color/colorPrimary"
    android:layout_alignParentBottom="true"
    android:id="@+id/tabs"

    app:layout_collapseMode="parallax"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"

    xmlns:android="http://schemas.android.com/apk/res/android">


    </android.support.design.widget.TabLayout></android.support.design.widget.CoordinatorLayout>

第三片段布局:

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

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:hint="Enter something"
        />
</LinearLayout>

解决方法

打开AndroidManifest.xml并添加到您的活动代码中
机器人:windowSoftInputMode = “adjustPan”

如果这不起作用
机器人:windowSoftInputMode = “adjustnothing”

这将阻止软键盘调整布局.

希望这可以帮助.

今天的关于android – 如何在使用setTextIsSelectable禁用键盘后启用键盘android 关闭键盘的分享已经结束,谢谢您的关注,如果想了解更多关于Android Extend BaseExpandableListAdapter、Android SetText更改键盘类型、Android TextView settextcolor selected、android – (tablayout)当editText聚焦时,标签会越过键盘的相关知识,请在本站进行查询。

本文标签: