2017-11-17 22 views

答えて

0

ボタンの色の変化につながる次のボタンについては、ここで解決しています。

チェックボタンとeditext属性。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:id="@+id/frameContainer" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:orientation="vertical" 
       android:padding="16dp" 
       tools:context="com.android.buffer.exampleapplication.MainActivity"> 

    <EditText 
     android:id="@+id/etFocus" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:hint="enter name" 
     android:maxLines="1" 
     android:imeOptions="actionNext" 
     android:singleLine="true"/> 

    <Button 
     android:id="@+id/btn" 
     android:focusableInTouchMode="true" 
     android:focusable="true" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="Button"/> 

</LinearLayout> 

ここでは動作させるコードです。

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     final Button button = findViewById(R.id.btn); 
     final EditText editText = findViewById(R.id.etFocus); 
     editText.setNextFocusDownId(R.id.btn); 
     editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
      @Override 
      public boolean onEditorAction(final TextView textView, final int i, final KeyEvent keyEvent) { 
       if (i== EditorInfo.IME_ACTION_NEXT){ 
        editText.clearFocus(); 
        button.requestFocus(); 
       } 
       return false; 
      } 
     }); 
     button.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
      @Override 
      public void onFocusChange(final View view, final boolean b) { 
       if (view.isFocused()){ 
        button.setBackgroundResource(R.color.colorAccent); 
       } 
      } 
     }); 
    } 
関連する問題