禁用edittext并滚动水平

时间:2012-09-17 12:21:11

标签: android android-edittext

我希望在禁用EditText时进行滚动,并在1行中包含大文本。

我尝试edittext.setInputType(InputType.TYPE_NULL)

但背景不会改变,用户无法分辨是否可以进行编辑。

编辑:我的xml:

<EditText
                android:id="@+id/et_address"
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:inputType="text"
                android:maxLength="120"
                android:maxLines="1"
                android:singleLine="true"
                android:nextFocusDown="@+id/et_name" />

当启用edittext时水平滚动工作正常,我想在禁止编辑文本时使用相同的

6 个答案:

答案 0 :(得分:4)

更好地使用textview并使用XML样式设置背景,例如edittext

            <TextView
                android:id="@+id/output"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="2dp"
                android:layout_marginTop="2dp"
                android:layout_weight="1"
                android:background="@drawable/btnstyle"
                android:hint="@string/convert"
                android:inputType="number"
                android:textColor="#000000"
                android:scrollbars="horizontal"
                android:scrollHorizontally="true"
                android:gravity="left|center"
                android:textSize="18sp"

               />

并设置

        Output = (TextView) findViewById(R.id.output);
        Output.setMovementMethod(new ScrollingMovementMethod());

希望这个有用

答案 1 :(得分:2)

您可以在edittext中使用以下参数。

et.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
et.setHintTextColor(Color.TRANSPARENT);
et.setFocusable(false);
et.setClickable(false);
et.setFocusableInTouchMode(false);
et.setEnabled(true);
et.setKeyListener(null);
et.setHorizontallyScrolling(true);

因此,当按下编辑时,它将作为所需的行为工作,否则将表现为文本视图。

答案 2 :(得分:1)

尝试使用xml中的android:singleLine="true"作为单行,并增加大文本的字体大小。对于滚动,你能描述出你想要的吗?

答案 3 :(得分:0)

简短回答:

        <EditText
            android:id="@+id/et_1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:ems="10"
            android:focusableInTouchMode="false"
            android:scrollHorizontally="true" />

示例,如何使用PopUpWindow代替默认键盘:

        //Your Main Layout        
        RelativeLayout mainLayout = (RelativeLayout)findViewById(R.id.activity_rl);

        LayoutInflater layoutInflater = (LayoutInflater)getBaseContext()
                .getSystemService(LAYOUT_INFLATER_SERVICE);
        //Set layout instead keyboard (Linear layout with buttons)  
        View popupView = layoutInflater.inflate(R.layout.keyboard, null);  
        PopupWindow ppwin = new PopupWindow(popupView, LayoutParams.FILL_PARENT,  
        LayoutParams.WRAP_CONTENT);
        //Some Button on that Linear layout
        Button bt = (Button)popupView.findViewById(R.id.button1);
        bt.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    edit_text.setText(edit_text.getText().toString()+"Your text");
                }
        });
       //Your EditText in Main layout 
        EditText edit_text = (EditText)findViewById(R.id.et_1);
        edit_text .setOnTouchListener(new OnTouchListener() {
                @Override public boolean onTouch(View v, MotionEvent event) {
                    //show PopUpWindow with buttons instead default keyboard
                    //or your custom keyboard
                    ppwin.showAtLocation(mainLayout, Gravity.BOTTOM, 0, 0);
                    return false;
                }
       });

答案 4 :(得分:0)

EditText et= (EditText) findViewById(R.id.et_address);
et.setMovementMethod(new ScrollingMovementMethod());

答案 5 :(得分:0)

XML

 android:singleLine="true"
 android:scrollHorizontally="true"

代码

myEditText.setKeyListener(null);

这样,将不会启用编辑文本,并且可以进行滚动。您也可以将editText的文本颜色更改为#d3d3d3。与setEnabled(false)

具有相同的外观

为我工作, 希望对别人有帮助