2017-03-27 5 views

Antwort

0

Sie können eine Methode aus Aktivität verwenden, die aufgerufen wird: getRequestedOrientation()

So können Sie tun:

if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { 
     dLayout.setBackgroundColor(getResources().getColor(R.color.bpblack)); 
    } else { 
     dLayout.setBackgroundColor(getResources().getColor(R.color.bpBlue)); 
    } 

Setzen Sie dieses auf yout Aktivität des onCreate und jedes Mal, wenn Sie Ihre Ausrichtung ändern, onCreate Wird wieder aufgerufen und Ihr Hintergrund ändert seine Farbe.

Viel Glück.

+0

es hat nicht funktioniert, wenn ich die App stoppt das Gerät Orientierung ändern, hier mein Code: 'protected void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); Ll = (LinearLayout) this.findViewById (R.id.layo); txt = (Textansicht) findViewById (R.id.text); if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { Ll.setBackgroundColor ((Color.GREEN)); } else { Ll.setBackgroundColor ((Color.BLACK)); } ' –

Verwandte Themen