Проблема AppCompatDialogFragment с appcompat-v7:23.1.0
Я updgraded appcompat v7
версии 23.0.1 для версии 23.1.0
и я нашел этот сюрприз в отношении AppCompatDialogFragment
:
в верхней части диалогового окна появляется дополнительное пространство
кто-нибудь еще испытывает?
вот мой код:
public class AlertDialogFragment extends AppCompatDialogFragment {
public static final int ALERTDIALOG_STARTUP = 101;
public static final int ALERTDIALOG_DELETE_SEARCH_HISTORY = 102;
public static final int ALERTDIALOG_RATE_APP = 103;
public static final int ALERTDIALOG_REACHED_FOLLOWS_FREE_LIMIT = 104;
public static final int ALERTDIALOG_UNFOLLOW_ROUTE = 105;
AlertDialogListener mListener;
public static AlertDialogFragment newInstance(int type, String id, String[] params) {
AlertDialogFragment frag = new AlertDialogFragment();
Bundle args = new Bundle();
args.putInt("type", type);
args.putString("id", id);
args.putStringArray("params", params);
frag.setArguments(args);
return frag;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onAttach(Context activity) {
super.onAttach(activity);
try {
mListener = (AlertDialogListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement AlertDialogListener");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.view_alertdialog, container, false);
int type = getArguments().getInt("type");
String[] params = getArguments().getStringArray("params");
switch (type) {
case ALERTDIALOG_STARTUP:
setCancelable(false);
view = setupView(view, getString(R.string.startup_title), getString(R.string.startup_message), getString(R.string.go_to_facebook), getString(R.string.go_to_app));
break;
case ALERTDIALOG_DELETE_SEARCH_HISTORY:
view = setupView(view, params[0], getString(R.string.remove_search_message), getString(android.R.string.yes), getString(android.R.string.no));
break;
case ALERTDIALOG_RATE_APP:
setCancelable(false);
view = setupView(view, getString(R.string.rate_app_title), getString(R.string.rate_app_message), getString(R.string.rate_app_yes), getString(R.string.rate_app_no));
break;
case ALERTDIALOG_REACHED_FOLLOWS_FREE_LIMIT:
view = setupView(view, params[0], params[1], params[2], null);
break;
case ALERTDIALOG_UNFOLLOW_ROUTE:
view = setupView(view, params[0], getString(R.string.unfollow_route_message), getString(android.R.string.yes), getString(android.R.string.no));
break;
}
return view;
}
private View setupView(View view, String title, String text, String positiveButtonLabel, String negativeButtonLabel) {
TextView customTitle = (TextView) view.findViewById(R.id.custom_title);
customTitle.setText(title);
TextView customMessage = (TextView) view.findViewById(R.id.custom_message);
customMessage.setText(Html.fromHtml(text));
if (positiveButtonLabel!=null) {
Button positiveButton = (Button) view.findViewById(R.id.positive_button);
positiveButton.setVisibility(View.VISIBLE);
positiveButton.setText(positiveButtonLabel);
positiveButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mListener.onAlertDialogPositiveClick(getArguments().getInt("type"), getArguments().getString("id"));
dismiss();
}
});
}
if (negativeButtonLabel!=null) {
Button negativeButton = (Button) view.findViewById(R.id.negative_button);
negativeButton.setVisibility(View.VISIBLE);
negativeButton.setText(negativeButtonLabel);
negativeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
mListener.onAlertDialogNegativeClick(getArguments().getInt("type"), getArguments().getString("id"));
dismiss();
}
});
}
return view;
}
public interface AlertDialogListener {
public void onAlertDialogPositiveClick(int dialogType, String id);
public void onAlertDialogNegativeClick(int dialogType, String id);
}
}
здесь view_alertdialog.xml
формат:
<LinearLayout
android:orientation="vertical"
android:paddingTop="@dimen/alert_dialog_padding_top"
android:paddingLeft="@dimen/alert_dialog_padding_hor"
android:paddingRight="@dimen/alert_dialog_padding_hor"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/custom_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/evidence_color"
android:textStyle="bold"
android:textSize="@dimen/alert_dialog_title_textsize" />
<TextView
android:id="@+id/custom_message"
android:layout_marginTop="@dimen/about_activity_paragraph_marginTop"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/top_color"
android:textSize="@dimen/alert_dialog_message_textsize" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
style="?attr/buttonBarStyle">
<Button
android:id="@+id/negative_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/cancel"
android:textStyle="bold"
android:textColor="@color/link_color"
android:visibility="gone"
style="?attr/buttonBarButtonStyle"/>
<Button
android:id="@+id/positive_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@android:string/ok"
android:textStyle="bold"
android:textColor="@color/link_color"
android:visibility="gone"
style="?attr/buttonBarButtonStyle"/>
</LinearLayout>
</LinearLayout>
1 ответов
это заголовок AppCompatDialogFragment
. Вы можете скрыть название с помощью этого кода:
public class AlertDialogFragment extends AppCompatDialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NO_TITLE, 0);
}
}