在 Android 2.3.4 上使用 Sherlock:我想展示一个AlertDialog
包含:
1)A 标题
2)A 内容
3)2 按钮
我正在使用以下类:
public class MyAlertDialog extends SherlockDialogFragment{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the Builder class for convenient dialog construction
AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
builder.setMessage("Title")
.setPositiveButton("Fire!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
return builder.create();
}
}
在我的活动中,我正在打电话:
MyAlertDialog m = new MyAlertDialog();
m.show(getSupportFragmentManager(), "hey");
它正在显示 AlertDialog 但使用旧主题(请记住我使用的是 Android 2.3.4)
如果您愿意,这是我的整个主要活动课程:
public class MainActivity extends SherlockFragmentActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActionBar ab;
ab = getSupportActionBar();
ab.setTitle("Testing Sherlock");
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getSupportMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId())
{
case R.id.action_one:
MyAlertDialog m = new MyAlertDialog();
m.show(getSupportFragmentManager(), "hey");
break;
}
return super.onOptionsItemSelected(item);
}
}
我为我的应用设置的样式是:
<resources>
<style name="AppBaseTheme" parent="@style/Theme.Sherlock.Light">
</resources>
PS:我有ActionBar
显示,除了主题之外一切正常AlertDialog
。
我希望它看起来像这样:
而不是这样的: