3

我想在 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时水平滚动效果很好,我希望禁用edittext时也一样

4

6 回答 6

5

更好地使用 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());

希望这有帮助

于 2012-11-24T10:49:34.847 回答
2

您可以在编辑文本中使用以下参数。

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);

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

于 2014-08-21T06:55:24.613 回答
1

在您的 xml 中尝试android:singleLine="true" 单行并增加大文本的字体大小。对于滚动,您能准确描述您想要的吗?

于 2012-09-17T12:29:21.423 回答
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;
                }
       });
于 2013-10-22T09:04:15.463 回答
0

XML

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

代码

myEditText.setKeyListener(null);

这样编辑文本没有启用并且滚动工作。您还可以将 editText 的文本颜色更改为#d3d3d3. 拥有相同的外观setEnabled(false)

为我工作,希望它可以帮助某人

于 2019-07-08T11:21:09.390 回答
0
EditText et= (EditText) findViewById(R.id.et_address);
et.setMovementMethod(new ScrollingMovementMethod());
于 2017-10-14T06:53:17.227 回答