thenosic
thenosic

Reputation: 1495

edittext disabled and scroll horizontal

I want to do scroll when the EditText is disabled and contains a large text in 1 line.

I try edittext.setInputType(InputType.TYPE_NULL)

but background don't change, and users can not tell the difference when they can edit or not.

EDIT: my 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" />

the horizontal scroll works fine when edittext is enable, i want the same when edittext turn disabled

Upvotes: 4

Views: 7516

Answers (7)

zakaria-alshamere
zakaria-alshamere

Reputation: 43

The EditText that needs several attributes is the search field, such as the field of the Google search engine

You can do it like this

<EditText
                                android:layout_width="match_parent"
                                android:layout_height="40dp"
                                android:scrollbars="horizontal"
                                android:scrollHorizontally="true"
                                android:singleLine="true" 
                                android:background="#FFF"
                                android:paddingHorizontal="10dp"
                                android:gravity="center_vertical"
                                android:hint="search"
                                android:textSize="12sp" />

Upvotes: 0

XML

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

Code

myEditText.setKeyListener(null);

This way the edit text is not enabled and the scrolling works. You can also change the color of the text of the editText to #d3d3d3. To have the same apperance as setEnabled(false)

Worked for me, Hope it helps someone

Upvotes: 1

Devraj Jha
Devraj Jha

Reputation: 11

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

Upvotes: 0

Google
Google

Reputation: 2223

try the android:singleLine="true" in your xml for single line and increase the font size for large text. for scroll can you describe the exactly what you want?

Upvotes: 1

Vyshnavi
Vyshnavi

Reputation: 338

You can use the following parameters in the 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);

So that when edit is pressed, it will work as the desired behaviour and else will behave as text view.

Upvotes: 3

user2556552
user2556552

Reputation:

Short answer:

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

Example, how to use PopUpWindow instead default keyboard:

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

Upvotes: 0

APriya
APriya

Reputation: 2004

Better use textview and set background like edittext using XML style

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

               />

and set

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

Hope this Helpful

Upvotes: 5

Related Questions