Cách tôi có thể thay đổi màu nền của thanh tiêu đề mà không cần sử dụng chủ đề. tnks trong Android.Cách thay đổi màu của thanh tiêu đề không có chủ đề
5
A
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);
}
}
-1
Tôi nghĩ dicussion khác này sẽ rất hữu ích cho bạn:
+0
Anh ấy đặc biệt yêu cầu ** không có chủ đề **. – 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 –
android.R.id.titlebar nơi tôi tìm thấy nó hoặc nơi tôi tạo ra nó ??? – Friz14
tkns i tìm thấy nó ì :) – Friz14
@ 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