Tôi đang cố gắng thay đổi nền của ActionBar từ một Trình xử lý. Mục tiêu cuối cùng là truyền Handler cho AsyncTask, nhưng bây giờ thậm chí còn gọi Handler.sendMessage() từ một kết quả Thread trong hành vi lạ. Thông qua trình gỡ lỗi, tôi có thể thấy rằng Trình xử lý nhận được Thư và sau đó chạy setActionBarBackground() đến hết.ActionBar setBackgroundDrawable() nulling background from Thread/Handler
ActionBar mặc định với đột quỵ dưới cùng màu xanh hoàn toàn biến mất khỏi màn hình và không được thay thế bằng GradientDrawable mới. Tôi nghi ngờ rằng nền tảng đang bị vô hiệu hóa bằng cách nào đó. Hơn nữa, khi tôi tập trung vào EditText một lần nữa, nền ActionBar GradientDrawable chính xác xuất hiện. Các hành vi tôi mong đợi là cho nền để thay đổi đơn giản trên actionDone.
Bất kỳ thông tin chi tiết nào về lý do tại sao điều này đang xảy ra sẽ được đánh giá rất nhiều!
đang liên quan:
TestActivity.java
public class TestActivity extends RoboSherlockFragmentActivity {
@InjectView(R.id.ET_test) EditText testET;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(MainApp.TAG, "onCreate");
setContentView(R.layout.test_activity);
testET.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
if (i == EditorInfo.IME_ACTION_DONE) {
String loc = testET.getText().toString();
InputMethodManager mgr = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(testET.getWindowToken(), 0);
Toast.makeText(TestActivity.this, "EditText done!", Toast.LENGTH_SHORT).show();
/*TestQuery tq = new TestQuery(TestActivity.this, mHandler);
tq.execute();*/
new Thread(new Runnable() {
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mHandler.sendMessage(new Message());
}
}).start();
}
return true;
}
});
}
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
//setActivityColors();
setActionBarBackground();
}
};
private void setActionBarBackground() {
ActionBar ab = getSupportActionBar();
//Drawable d = WidgetUtils.getActionBarDrawable(TestActivity.this, 0xFF00FFFF);
GradientDrawable gd = new GradientDrawable(
GradientDrawable.Orientation.TOP_BOTTOM,
new int[]{0xFFFFFFFF, 0xFF000000});
gd.setCornerRadius(0f);
ab.setBackgroundDrawable(gd);
}
}
test_activity.xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="button"/>
<EditText
android:id="@+id/ET_test"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="true"
android:maxLines="1"
android:lines="1"
android:inputType="number"
android:imeOptions="actionDone"
android:nextFocusUp="@id/ET_test"
android:nextFocusLeft="@id/ET_test"/>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="button2"/>
</LinearLayout>
Tác vụ này không cần thiết. –
nhờ @Mat làm việc cho tôi nhưng nếu bạn cần Tiêu đề bạn chỉ có thể thay đổi trạng thái của tiêu đề cho phép :) – Antarix
Nếu bạn không biết nếu tiêu đề được hiển thị hoặc không làm việc này: \t \t \t boolean isDisplayingTitle = (actionBar.getDisplayOptions() & ActionBar.DISPLAY_SHOW_TITLE)! = 0; actionBar.setDisplayShowTitleEnabled (! IsDisplayingTitle); actionBar.setDisplayShowTitleEnabled (isDisplayingTitle); –