0
我有一種方法可以根據是否在屏幕上決定是否更改導航欄的顏色。該方法已被編寫,但我不知道如何調用它。我用按鈕點擊事件調用這個方法,但這非常困難。希望他自動打電話,而不是點擊事件通話,我該怎麼辦?Android導航欄根據條件自動更改顏色
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));
}
}
發佈您迄今爲止試過的幫助瞭解問題 –
向我們顯示您的代碼。 –
你需要更清楚地瞭解這個「標準」的變化。它是什麼?你怎麼得到它? –