Fix custom action bars for Android 4.4

This commit is contained in:
Dominik Schürmann 2013-12-30 21:46:42 +01:00
parent 2c0b2e356b
commit 1be368092e
3 changed files with 10 additions and 40 deletions

View file

@ -81,8 +81,9 @@ public class ActionBarHelper {
cancelOnClickListener); cancelOnClickListener);
// Show the custom action bar view and hide the normal Home icon and title. // Show the custom action bar view and hide the normal Home icon and title.
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM actionBar.setDisplayShowTitleEnabled(false);
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams( actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
} }
@ -107,8 +108,9 @@ public class ActionBarHelper {
doneOnClickListener); doneOnClickListener);
// Show the custom action bar view and hide the normal Home icon and title. // Show the custom action bar view and hide the normal Home icon and title.
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM actionBar.setDisplayShowTitleEnabled(false);
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE); actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(customActionBarView); actionBar.setCustomView(customActionBarView);
} }

View file

@ -41,7 +41,7 @@ public class AppSettingsActivity extends SherlockFragmentActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Inflate a "Done" custom action bar view to serve as the "Up" affordance. // Inflate a "Done" custom action bar
ActionBarHelper.setDoneView(getSupportActionBar(), R.string.api_settings_save, ActionBarHelper.setDoneView(getSupportActionBar(), R.string.api_settings_save,
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override

View file

@ -58,10 +58,8 @@ import android.widget.CheckBox;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity; import com.actionbarsherlock.app.SherlockFragmentActivity;
public class EditKeyActivity extends SherlockFragmentActivity { public class EditKeyActivity extends SherlockFragmentActivity {
@ -81,8 +79,6 @@ public class EditKeyActivity extends SherlockFragmentActivity {
public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id"; public static final String RESULT_EXTRA_MASTER_KEY_ID = "master_key_id";
public static final String RESULT_EXTRA_USER_ID = "user_id"; public static final String RESULT_EXTRA_USER_ID = "user_id";
private ActionBar mActionBar;
private PGPSecretKeyRing mKeyRing = null; private PGPSecretKeyRing mKeyRing = null;
private SectionView mUserIdsView; private SectionView mUserIdsView;
@ -107,26 +103,15 @@ public class EditKeyActivity extends SherlockFragmentActivity {
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
// Inflate a "Done"/"Cancel" custom action bar view // Inflate a "Done"/"Cancel" custom action bar
final LayoutInflater inflater = (LayoutInflater) getSupportActionBar().getThemedContext() ActionBarHelper.setDoneCancelView(getSupportActionBar(), R.string.btn_save,
.getSystemService(LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(
R.layout.actionbar_custom_view_done_cancel, null);
((TextView) customActionBarView.findViewById(R.id.actionbar_done_text))
.setText(R.string.btn_save);
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
new View.OnClickListener() { new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// save // save
saveClicked(); saveClicked();
} }
}); }, R.string.btn_do_not_save, new View.OnClickListener() {
((TextView) customActionBarView.findViewById(R.id.actionbar_cancel_text))
.setText(R.string.btn_do_not_save);
customActionBarView.findViewById(R.id.actionbar_cancel).setOnClickListener(
new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
// cancel // cancel
@ -134,21 +119,8 @@ public class EditKeyActivity extends SherlockFragmentActivity {
} }
}); });
// Show the custom action bar view and hide the normal Home icon and title.
final ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
actionBar.setCustomView(customActionBarView, new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
setContentView(R.layout.edit_key); setContentView(R.layout.edit_key);
mActionBar = getSupportActionBar();
mActionBar.setDisplayShowTitleEnabled(true);
// set actionbar without home button if called from another app
ActionBarHelper.setBackButton(this);
// find views // find views
mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase); mChangePassPhrase = (Button) findViewById(R.id.edit_key_btn_change_pass_phrase);
mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase); mNoPassphrase = (CheckBox) findViewById(R.id.edit_key_no_passphrase);
@ -201,8 +173,6 @@ public class EditKeyActivity extends SherlockFragmentActivity {
private void handleActionCreateKey(Intent intent) { private void handleActionCreateKey(Intent intent) {
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
mActionBar.setTitle(R.string.title_create_key);
mCurrentPassPhrase = ""; mCurrentPassPhrase = "";
if (extras != null) { if (extras != null) {
@ -330,8 +300,6 @@ public class EditKeyActivity extends SherlockFragmentActivity {
private void handleActionEditKey(Intent intent) { private void handleActionEditKey(Intent intent) {
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
mActionBar.setTitle(R.string.title_edit_key);
if (extras != null) { if (extras != null) {
if (extras.containsKey(EXTRA_MASTER_CAN_SIGN)) { if (extras.containsKey(EXTRA_MASTER_CAN_SIGN)) {
masterCanSign = extras.getBoolean(EXTRA_MASTER_CAN_SIGN); masterCanSign = extras.getBoolean(EXTRA_MASTER_CAN_SIGN);