2015-08-16 2 views
1

Я в значительной степени следую this tutorial и хочу адаптировать макет AlertDialog к моим потребностям. Теперь мне нужно избавиться от разделителя между двумя кнопками в ButtonBar. Я изменил расположение моей Button так:Android AlertDialog удалить разделитель между Button.Borderless в ButtonBar

<style name="Widget.Sphinx.Button.Borderless.Small" parent="@android:style/Widget.Holo.Button.Borderless.Small"> 
     <item name="android:textColor">@color/button_textcolor</item> 
     <item name="android:background">@drawable/button</item> 
     <item name="android:layout_marginLeft">10dp</item> 
     <item name="android:layout_marginRight">10dp</item> 
     <item name="android:layout_marginBottom">10dp</item> 
     <item name="android:gravity">center</item> 
     <item name="android:textStyle">normal</item> 
     <item name="android:dividerVertical">@android:color/transparent</item> 
</style> 

enter image description here

Я попытался адаптировать ButtonBar макет, а также:

<style name="Sphinx.ButtonBar.AlertDialog" parent="@android:style/Holo.ButtonBar.AlertDialog"> 
     <item name="android:background">@android:color/transparent</item> 
     <item name="android:dividerHorizontal">@null</item> 
     <item name="android:dividerVertical">@null</item> 
</style> 

Я попытался установить в @null и @android:color/transparent без успеха. Каков правильный способ сделать это?

+1

Вы не можете удалить этот делитель. Вам нужно будет создать настраиваемый диалог и использовать надувной макет, раздувая ваш собственный макет с кнопками внутри него. Если вам нужна помощь, отправьте свой код AlertDialog. –

ответ

0

Как сказал Хусейн, его невозможно достичь с помощью стилизации темы. Так что я создал обычай AlertDialog вроде этого:

1) Создание Activity и установить это тема для диалога в AndroidManifest.xml

<activity 
     android:name=".BSADialogActivity" 
     android:label="@string/title_activity_dialog" 
     android:theme="@android:style/Theme.Holo.Light.Dialog" > 
    </activity> 

2) Создание пользовательского макета

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:weightSum="1"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="10dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="Edit Topic" 
     android:id="@+id/textView2" 
     android:textColor="@color/purple" 
     android:background="@color/green_light" 
     android:gravity="center" /> 

    <EditText 
     android:id="@+id/et_topic" 
     android:inputType="text" 
     android:textColor="@color/purple" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="16dp" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginBottom="5dp"/> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:id="@+id/bt_cancel" 
      android:background="@drawable/button" 
      android:src="@android:drawable/ic_menu_close_clear_cancel" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <ImageButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp" 
      android:id="@+id/bt_ok" 
      android:background="@drawable/button" 
      android:src="@android:drawable/ic_menu_save" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" /> 
    </RelativeLayout> 
</LinearLayout> 

3) Запустите Диалог

Intent dialogIntent = new Intent(getActivity(), BSADialogActivity.class); 
dialogIntent.putExtra(BSAMainActivity.EXTRA_TOPIC, mTopic); 
getActivity().startActivityForResult(dialogIntent, SAMainActivity.REQUEST_DIALOG); 

4) Посмотрите на результат

enter image description here

5) Ручка ImageButton события в DialogActivity

ImageButton ibSave = (ImageButton) findViewById(R.id.bt_ok); 
    ibSave.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      Intent i = new Intent(); 
      i.putExtra(BSAMainActivity.EXTRA_TOPIC, etTopic.getText().toString()); 
      setResult(RESULT_OK, i); 
      finish(); 
     } 
    }); 

6) Обрабатывать результаты в MainAcitivty

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    // Check which request we're responding to 
    if (requestCode == REQUEST_DIALOG) { 
     if (resultCode == RESULT_OK) { 
      Fragment fragment = getSupportFragmentManager().findFragmentByTag(BSA_CHAT_TAG); 
      if (fragment instanceof BSABluetoothChatFragment) { 
       ((BSABluetoothChatFragment) fragment).updateTopic(data.getStringExtra(EXTRA_TOPIC)); 
      } 
     } 
    } 
    super.onActivityResult(requestCode, resultCode, data); 
} 
Смежные вопросы