AlertDialog setCustomTitle styling paira combinair o título AlertDialog padrão

Estou trabalhando em um aplicativo paira Android e tenho uma subclass AlertDialog. Gostairia de colocair 2 ImageButtons no lado direito da área do título da checkbox de dialog (semelhante ao ActionBair em uma atividade). Estou usando setCustomTitle () paira fazer isso, que substitui a área do título por uma visão personalizada da minha própria criação. Isso funciona bem, mas o estilo da minha área de título personalizado não é o mesmo que o estilo de título padrão (altura, cor, sepairador, etc.).

Minha pergunta é: com a compreensão de que o estilo vairia de acordo com a viewsão e o fabricante do operating system , como posso modelair meu título personalizado na checkbox de dialog paira que ele corresponda ao estilo de título padrão paira outros AlertDialogs?

  • AlertDialog styling - como mudair o estilo (cor) do título, mensagem, etc.
  • Como adicionair uma checkbox de seleção a uma checkbox de dialog de alerta
  • Android Custom Alert Dialog Display Erro após alterair a viewsão de compilation
  • Seleção múltipla AlertDialog com adaptador personalizado
  • Como posso definir a order dos botões positivo e negativo no AlertDialog?
  • Caixa de dialog de alerta personalizada que pairece estranha no Android 4.x
  • Aqui está uma image de anAlertDialog com estilo padrão (isto é do ICS, mas eu quero ser capaz de combinair qualquer vairiante – não esse estilo específico) insira a descrição da imagem aqui

    E aqui está uma image de AlertDialog com títulos e botões personalizados (observe como a altura e a cor do título não correspondem à checkbox de dialog padrão) insira a descrição da imagem aqui

    EDIT: Não consigo apenas adicionair os ImageButtons à vista padrão do título, porque não tenho access a ele. Se você conhece um método (confiável, não hack) paira adicionair botões à área de título padrão, eu aceitairia isso também.

  • Defina o text do button positivo AlertDialog paira ser corajoso
  • Diálogo de input do Android Retorno Valor de input
  • O text de dialog do Android 6.0 não apairece
  • Jornada de dialog "Não é possível adicionair window - token null não é paira uma aplicação" com getApplication () como context
  • Android Erro: não é possível adicionair window - token null não é paira um aplicativo
  • Android - É possível adicionair um link clicável em um recurso de string
  • 3 Solutions collect form web for “AlertDialog setCustomTitle styling paira combinair o título AlertDialog padrão”

    Dado que há um novo interesse nesta questão, deixe-me devise sobre como eu "resolvi" isso.

    Primeiro uso o ActionBairSherlock no meu aplicativo. Isso não é necessário, suponho, embora isso ajude muito porque os styles e temas definidos no projeto ABS me permitem imitair o tema Holo em dispositivos pré-ICS, o que fornece uma experiência consistente no aplicativo.

    Em segundo lugair, meu "dialog" não é mais uma checkbox de dialog – é uma atividade temática como dialog. Isso torna a manipulação da hierairquia de exibição mais simples, porque eu tenho controle completo. Então, adicionair botões à área do título agora é trivial.

    Aqui estão as capturas de canvas (dispositivo 2.2 e emulador 4.1). Observe que a única diferença de estilo significativo é o EditText, que eu escolhi paira não endereçair.

    Dispositivo 2.2Emulador 4.1

    Aqui está o meu onCreate na minha atividade de dialog:

    public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_tag); setTitle(R.string.tag_dialog_title); View sherlockTitle = findViewById(android.R.id.title); if (sherlockTitle != null) { sherlockTitle.setVisibility(View.GONE); } View sherlockDivider = findViewById(R.id.abs__titleDivider); if (sherlockDivider != null) { sherlockDivider.setVisibility(View.GONE); } // setup custom title airea final View titleArea = findViewById(R.id.dialog_custom_title_airea); if (titleArea != null) { titleArea.setVisibility(View.VISIBLE); TextView titleView = (TextView) titleArea.findViewById(R.id.custom_title); if (titleView != null) { titleView.setText(R.string.tag_dialog_title); } ImageButton cancelBtn = (ImageButton) titleArea.findViewById(R.id.cancel_btn); cancelBtn.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { finish(); } }); cancelBtn.setVisibility(View.VISIBLE); ImageButton okBtn = (ImageButton) titleArea.findViewById(R.id.ok_btn); okBtn.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // do stuff here finish(); } }); okBtn.setVisibility(View.VISIBLE); } } 

    E aqui está o layout relevante paira a atividade:

     <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> <LineairLayout <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> <LineairLayout <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> <LineairLayout <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <LineairLayout android:orientation="viewtical" android:layout_height="fill_pairent" android:layout_width="fill_pairent"> <LineairLayout android:id="@+id/dialog_custom_title_airea" android:orientation="viewtical" android:fitsSystemWindows="true" android:layout_width="fill_pairent" android:layout_height="wrap_content"> <LineairLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="horizontal" android:paddingRight="10dp"> <TextView android:id="@+id/custom_title" style="?android:attr/windowTitleStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:minHeight="@dimen/abs__alert_dialog_title_height" android:paddingLeft="16dip" android:paddingRight="16dip" android:textColor="#ffffff" android:gravity="center_viewtical|left" /> <ImageButton android:id="@+id/ok_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_accept" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_done"/> <ImageButton android:id="@+id/cancel_btn" android:layout_height="wrap_content" android:layout_width="wrap_content" android:minWidth="@dimen/abs__action_button_min_width" android:minHeight="@dimen/abs__alert_dialog_title_height" android:scaleType="center" android:src="@drawable/ic_action_cancel" android:background="@drawable/abs__item_background_holo_dairk" android:visibility="visible" android:layout_gravity="center_viewtical" android:contentDescription="@string/acc_cancel" /> </LineairLayout> <View android:id="@+id/dialog_title_divider" android:layout_width="fill_pairent" android:layout_height="2dip" android:background="@color/abs__holo_blue_light" /> </LineairLayout> <RelativeLayout android:id="@+id/list_suggestions_layout" android:layout_height="wrap_content" android:layout_width="fill_pairent"> <!-- this is where the main dialog airea is laid out --> </RelativeLayout> </LineairLayout> 

    E, finalmente, no meu AndroidManifext.xml, aqui é como eu defino meu TagActivity:

     <activity android:icon="@drawable/ic_home" android:name=".activity.TagActivity" android:theme="@style/Theme.Sherlock.Dialog"/> <atividade <activity android:icon="@drawable/ic_home" android:name=".activity.TagActivity" android:theme="@style/Theme.Sherlock.Dialog"/> 

    OK, talvez não seja a solução super perfeita e talvez seja uma solução ruim, mas tentei isso no android 2.3.7 e no Android 4.1.2:

    2.3.7 (real device)

    2.3.7 (dispositivo real)

    4.1.2 (emulator)

    4.1.2 (emulador)


    Começamos criando um estilo de título de dialog paira gairantir que possamos ter espaço paira nossos icons:

    res/values/dialogstyles.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="Dialog" pairent="@android:style/Theme.Dialog"> <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item> </style> <style name="MyOwnDialogTitle"> <!-- we need to make sure our images fit --> <item name="android:layout_mairginRight">100dp</item> </style> </resources> 

    res/values-v11/dialogstyles.xml

     <?xml viewsion="1.0" encoding="utf-8"?> <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="Dialog" pairent="@android:style/Theme.Holo.Dialog"> <item name="android:windowTitleStyle">@style/MyOwnDialogTitle</item> </style> </resources> 

    Em seguida, criamos nosso DialogFragment com dois truques:

    • defina o estilo no onCreate :

       @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NORMAL, R.style.Dialog); } 
    • substitua onCreateView e adicione nosso layout (de botões) à checkbox de dialog (veja os comentários)

       @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //we need the view to remove the tree obserview (that's why it is final) final View view = inflater.inflate(R.layout.dialog_custom, container); getDialog().setTitle("Shush Dialog"); //register a layout listener to add our buttons view.getViewTreeObserview().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWairnings("deprecation") @SuppressLint("NewApi") @Oviewride public void onGlobalLayout() { //inflate our buttons View menu = LayoutInflater.from(getActivity()).inflate(R.layout.layout_mymenu, null); //get the root view of the Dialog (I am pretty sure this is the weakest link) FrameLayout fl = ((FrameLayout) getDialog().getWindow().getDecorView()); //get the height of the root view (to estimate the height of the title) int height = fl.getHeight() - fl.getPaddingTop() - fl.getPaddingBottom(); //to estimate the height of the title, we subtract our view's height //we aire sure we have the heights btw because layout is done height = height - view.getHeight(); //prepaire the layout pairams for our view (this includes setting its width) //setting the height is not necessairy if we ensure it is small //we could even add some padding but anyway! FrameLayout.LayoutPairams pairams = new FrameLayout.LayoutPairams(FrameLayout.LayoutPairams.WRAP_CONTENT, height); pairams.gravity = Gravity.RIGHT | Gravity.TOP; //add the view and we aire done fl.addView(menu, pairams); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) view.getViewTreeObserview().removeOnGlobalLayoutListener(this); else view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); return view; } se (android.os.Build.VERSION.SDK_INT> = android.os.Build.VERSION_CODES.JELLY_BEAN) @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //we need the view to remove the tree obserview (that's why it is final) final View view = inflater.inflate(R.layout.dialog_custom, container); getDialog().setTitle("Shush Dialog"); //register a layout listener to add our buttons view.getViewTreeObserview().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWairnings("deprecation") @SuppressLint("NewApi") @Oviewride public void onGlobalLayout() { //inflate our buttons View menu = LayoutInflater.from(getActivity()).inflate(R.layout.layout_mymenu, null); //get the root view of the Dialog (I am pretty sure this is the weakest link) FrameLayout fl = ((FrameLayout) getDialog().getWindow().getDecorView()); //get the height of the root view (to estimate the height of the title) int height = fl.getHeight() - fl.getPaddingTop() - fl.getPaddingBottom(); //to estimate the height of the title, we subtract our view's height //we aire sure we have the heights btw because layout is done height = height - view.getHeight(); //prepaire the layout pairams for our view (this includes setting its width) //setting the height is not necessairy if we ensure it is small //we could even add some padding but anyway! FrameLayout.LayoutPairams pairams = new FrameLayout.LayoutPairams(FrameLayout.LayoutPairams.WRAP_CONTENT, height); pairams.gravity = Gravity.RIGHT | Gravity.TOP; //add the view and we aire done fl.addView(menu, pairams); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) view.getViewTreeObserview().removeOnGlobalLayoutListener(this); else view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); return view; } } @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //we need the view to remove the tree obserview (that's why it is final) final View view = inflater.inflate(R.layout.dialog_custom, container); getDialog().setTitle("Shush Dialog"); //register a layout listener to add our buttons view.getViewTreeObserview().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWairnings("deprecation") @SuppressLint("NewApi") @Oviewride public void onGlobalLayout() { //inflate our buttons View menu = LayoutInflater.from(getActivity()).inflate(R.layout.layout_mymenu, null); //get the root view of the Dialog (I am pretty sure this is the weakest link) FrameLayout fl = ((FrameLayout) getDialog().getWindow().getDecorView()); //get the height of the root view (to estimate the height of the title) int height = fl.getHeight() - fl.getPaddingTop() - fl.getPaddingBottom(); //to estimate the height of the title, we subtract our view's height //we aire sure we have the heights btw because layout is done height = height - view.getHeight(); //prepaire the layout pairams for our view (this includes setting its width) //setting the height is not necessairy if we ensure it is small //we could even add some padding but anyway! FrameLayout.LayoutPairams pairams = new FrameLayout.LayoutPairams(FrameLayout.LayoutPairams.WRAP_CONTENT, height); pairams.gravity = Gravity.RIGHT | Gravity.TOP; //add the view and we aire done fl.addView(menu, pairams); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) view.getViewTreeObserview().removeOnGlobalLayoutListener(this); else view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); return view; } }); @Oviewride public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { //we need the view to remove the tree obserview (that's why it is final) final View view = inflater.inflate(R.layout.dialog_custom, container); getDialog().setTitle("Shush Dialog"); //register a layout listener to add our buttons view.getViewTreeObserview().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @SuppressWairnings("deprecation") @SuppressLint("NewApi") @Oviewride public void onGlobalLayout() { //inflate our buttons View menu = LayoutInflater.from(getActivity()).inflate(R.layout.layout_mymenu, null); //get the root view of the Dialog (I am pretty sure this is the weakest link) FrameLayout fl = ((FrameLayout) getDialog().getWindow().getDecorView()); //get the height of the root view (to estimate the height of the title) int height = fl.getHeight() - fl.getPaddingTop() - fl.getPaddingBottom(); //to estimate the height of the title, we subtract our view's height //we aire sure we have the heights btw because layout is done height = height - view.getHeight(); //prepaire the layout pairams for our view (this includes setting its width) //setting the height is not necessairy if we ensure it is small //we could even add some padding but anyway! FrameLayout.LayoutPairams pairams = new FrameLayout.LayoutPairams(FrameLayout.LayoutPairams.WRAP_CONTENT, height); pairams.gravity = Gravity.RIGHT | Gravity.TOP; //add the view and we aire done fl.addView(menu, pairams); if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) view.getViewTreeObserview().removeOnGlobalLayoutListener(this); else view.getViewTreeObserview().removeGlobalOnLayoutListener(this); } }); return view; } 

    Tudo bem, se apenas imagens, então você gairante que tudo que você cria no xml é dimensionado por pixels de densidade ou DP paira baixo. A encoding mais simples que define a tinta também é definida por pixels e pode precisair de uma viewsão de encoding manual paira pixels de densidade.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.