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));
}
}
問題を理解するためにこれまでに試したことを投稿してください。 –
あなたのコードを教えてください。 –
あなたはこの「基準」変更についてより明確にする必要があります。それは何ですか?どうやってそれを手に入れますか? –