0
Android 앱에서 기기 방향에 따라 배경색을 변경하려면 어떻게해야하나요?기기 방향에 따라 배경 변경
장치가 세로 (세로 방향) 인 경우 노란색으로 변경하십시오.
가로 (가로) 인 경우 녹색으로 변경하십시오.
Android 앱에서 기기 방향에 따라 배경색을 변경하려면 어떻게해야하나요?기기 방향에 따라 배경 변경
장치가 세로 (세로 방향) 인 경우 노란색으로 변경하십시오.
가로 (가로) 인 경우 녹색으로 변경하십시오.
: getRequestedOrientation는()
그래서 당신은 할 수 있습니다 :
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) {
dLayout.setBackgroundColor(getResources().getColor(R.color.bpblack));
} else {
dLayout.setBackgroundColor(getResources().getColor(R.color.bpBlue));
}
이 행해져 Yout 활동의에서 onCreate에 넣고 때마다 당신은 당신의 방향에서 onCreate 변경 다시 호출되고 배경색이 바뀝니다.
행운을 빈다.
장치 방향이 바뀌면 작동하지 않습니다. 내 코드는 다음과 같습니다. 'protected void onCreate (savedBundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Ll = (LinearLayout) this.findViewById (R.id.layo); txt = (TextView) findViewById (R.id.text); if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { Ll.setBackgroundColor ((Color.GREEN)); } else { Ll.setBackgroundColor ((Color.BLACK)); }' –