AlertDialog
Android 2.3.4でのSherlockの使用:以下を含むものを表示したいと思います:
1)タイトル
2)コンテンツ
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
。
私はそれをこのように見せたい:
そしてこれが好きではない: