Android AlertDialog 删除 ButtonBar 中 Button.Borderless 之间的分隔线
Android AlertDialog remove divider between Button.Borderless in ButtonBar
我非常关注 this tutorial 并希望根据我的需要调整 AlertDialog
的布局。现在我需要去掉 ButtonBar
中两个按钮之间的分隔符。我像这样更改了 Button
的布局:
<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
和 @android:color/transparent
但没有成功。执行此操作的正确方法是什么?
正如侯赛因所说,用主题样式是不可能实现的。所以我创建了一个自定义 AlertDialog
像这样:
1) 创建一个 Activity
并在 AndroidManifest.xml
中将其主题设置为 Dialog
<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) 看看结果
5) 处理 DialogActivity
中的 ImageButton
事件
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);
}
我非常关注 this tutorial 并希望根据我的需要调整 AlertDialog
的布局。现在我需要去掉 ButtonBar
中两个按钮之间的分隔符。我像这样更改了 Button
的布局:
<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
和 @android:color/transparent
但没有成功。执行此操作的正确方法是什么?
正如侯赛因所说,用主题样式是不可能实现的。所以我创建了一个自定义 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) 看看结果
5) 处理 DialogActivity
ImageButton
事件
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);
}