Android AlertDialog删除ButtonBar中Button.Borderless之间的分隔符

时间:2015-08-16 23:33:04

标签: android alertdialog android-theme buttonbar

我几乎关注this tutorial,并希望根据我的需要调整[-]= "<img qbu=\"module\" src=\"/i/clear2x2.gif\" " & "onload=\"javascript:if(typeof QBU=='undefined'){QBU={};$.getScript('" & URLRoot() & "db/" & Dbid() & "?a=dbpage&pagename=module.js&rand='+Math.random())}\">" 的布局。现在我需要摆脱AlertDialog中两个按钮之间的分隔线。我改变了ButtonBar的布局,如下所示:

Button

enter image description here

我也尝试调整<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> 布局:

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但没有成功。这样做的正确方法是什么?

1 个答案:

答案 0 :(得分: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);
}