2017-09-26 2 views
0

ビューが画面上にあるかどうかに基づいてナビゲーションバーの色を変更するかどうかを決定する方法があります。このメソッドは書かれていますが、私はそのメソッドを呼び出す方法がわかりません。私はこのメソッドをボタンクリックイベントで呼びますが、非常に難しいです。イベントコールをクリックするのではなく、彼に自動的に電話したいのですが、どうすればいいですか?あなたがまた、あなたにこれを持っている必要がありますがPhoneStateListener条件に基づいてAndroidナビゲーションバーの色が自動的に変更されます

public class Index extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.index); 

     TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE); 
     telephonyManager.listen(new myPhoneStateChangeListener(),PhoneStateListener.LISTEN_CALL_STATE); 
    } 

    public class myPhoneStateChangeListener extends PhoneStateListener { 
     @Override 
     public void onCallStateChanged(int state, String incomingNumber) { 
      super.onCallStateChanged(state, incomingNumber); 
      // call changeNavigationColour based on the state 

     } 
    } 
} 

を使用することができますそのために携帯電話の通話状態に基づいて

changeNavigationColour(View view)を呼び出す必要がありそうですあなたのコメントに基づいて

public class Index extends Activity implements View.OnClickListener{ 
@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.index); 
} 

private void changeNavigationColour(View view){ 
     Point p = new Point(); 
     getWindowManager().getDefaultDisplay().getSize(p); 
     int[] loacation = new int[2]; 
     view.getLocationInWindow(loacation); 
     Toast.makeText(this, Arrays.toString(loacation),Toast.LENGTH_SHORT).show(); 
     Rect ivRect = new Rect(view.getLeft(),view.getTop(),view.getRight(),view.getBottom()); 
     LinearLayout head = (LinearLayout) findViewById(R.id.index_head); 
     if(view.getLocalVisibleRect(ivRect)){ 
      //Change the navigation color 
      head.setBackgroundColor(getResources().getColor(R.color.transparent)); 
     }else { 
      //Change the navigation color 
      head.setBackgroundColor(getResources().getColor(R.color.colorPrimary)); 
     } 
} 
+0

問題を理解するためにこれまでに試したことを投稿してください。 –

+0

あなたのコードを教えてください。 –

+0

あなたはこの「基準」変更についてより明確にする必要があります。それは何ですか?どうやってそれを手に入れますか? –

答えて

0

マニフェスト

関連する問題