2011-07-05 39 views

Trả lời

4

Hãy thử với đoạn mã sau

View titleView = getWindow().findViewById(android.R.id.titlebar); 
    if (titleView != null) { 
     ViewParent parent = titleView.getParent(); 
     if (parent != null && (parent instanceof View)) { 
     View parentView = (View)parent; 
     parentView.setBackgroundColor(Color.RED); 
     } 
    } 
+3

android.R.id.titlebar nơi tôi tìm thấy nó hoặc nơi tôi tạo ra nó ??? – Friz14

+0

tkns i tìm thấy nó ì :) – Friz14

+1

@ Friz14 Bạn tìm thấy nó ở đâu? Tôi chạy vào [một vấn đề tương tự] (http://stackoverflow.com/q/11263829/869501) và tôi không thể tìm thấy 'android.R.id.titlebar'. Cảm ơn +1. – ateiob

0

ActionBar thanh = getActionBar(); bar.setBackgroundDrawable (new ColorDrawable (getResources(). GetColor (R.color.material_blue_gray1)));

+0

nếu bạn sử dụng android.support.v7.app.ActionBar sau đó sử dụng getSupportActionBar() thay cho getActionBar –

Các vấn đề liên quan