EditText 편집후 외부영역 클릭시 키보드 감추기

Posted by Albert 2819Day 7Hour 23Min 13Sec ago [2017-08-01]

//=========== xml view========

<RelativeLayout
android:id="@+id/content_sub"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@color/colorPrimaryDark"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="visionboy.com.qrcode.SettingActivity"
tools:showIn="@layout/app_bar_sub">
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/sub_swipe_layout"
>
<ListView
android:id="@+id/settingList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</android.support.v4.widget.SwipeRefreshLayout>

<EditText android:id="@+id/MemoBox"
android:layout_width="match_parent" android:layout_height="match_parent"
android:lines="5" android:gravity="top|left" android:inputType="textMultiLine"
android:scrollHorizontally="false"
android:minWidth="10.0dip"
android:maxWidth="5.0dip"
android:layout_margin="20dp"
android:padding="5dp"
android:background="@color/white"
android:visibility="invisible"
/>
</RelativeLayout>


//========java========== 

@Override
protected void onCreate(Bundle savedInstanceState) {
final DbManager dbManager = new DbManager(getApplicationContext());
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_setting);
    SwipeRefreshLayout sly = (SwipeRefreshLayout) findViewById(R.id.sub_swipe_layout);

sly.setVisibility(View.INVISIBLE);

m_Background = (ViewGroup) findViewById(R.id.content_sub);

m_Background.setOnClickListener(this);
}
@Override
public void onClick(View view) {
Toast toast = Toast.makeText(this, "Clicked Out side", Toast.LENGTH_SHORT);
if (m_Background == view) {
setSoftKeyboardVisible(this,false);
}
}

Editext 외부영역을 클릭시 키보드가 사라지는 효과이다. 그런데 한가지 주의점은 xml상  SwipeRefreshLayout 이 있을시에 외부영역 클릭효과가 사라진다.

왜냐면 드래그레프레시가 우선권을 차지해서 큭릭이 무효화되므로 외부영역클릭시 키보드 감춤 효과를 낼시 SwipeRefreshLayout 를 사용시 해당 activity에서는 잠간 숨김처리하면된다.

 




LIST

Copyright © 2014 visionboy.me All Right Reserved.