1
私はAPI21の後に古いダイアログがタイトルを失うことがわかりました。最小限のサンプルコードでは、API24とAPI26で、それがタイトルを表示することはできませんが、それはまだ私があれば思ったんだけど、タイトルを表示することができ、このDialogfragmentを作成して、DialogにAPI 21の後にtitleを付ける必要がありますか?
ようpublic class MainActivity extends AppCompatActivity {
private Button btn1;
private Dialog testDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
testDialog = new Dialog(MainActivity.this);
btn1 = (Button) findViewById(R.id.btnClick);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCopyDialog("some test");
}
});
}
private void showCopyDialog(final String address) {
testDialog.setTitle(address);
testDialog.setContentView(R.layout.copy_chip_dialog_layout);
testDialog.setCancelable(true);
testDialog.setCanceledOnTouchOutside(true);
Button button = (Button)testDialog.findViewById(android.R.id.button1);
String buttonTitle = "Button Title";
button.setText(buttonTitle);
testDialog.show();
}
}
そしてAPI21でcopy_chip_dialog_layout
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Copy Addresses"
android:id="@android:id/button1"
android:background="@null"
android:layout_gravity="left"/>
のレイアウトですDialogFragmentを作成してタイトルを追加する必要があります。
だから、基本的にDialogを直接使用することはできませんか? – litaoshen
appcompatライブラリのAlertdialogは古いAPIと新しいAPIを完全にサポートします –