我看到了this question以及this one和其他一些人,但没有任何帮助我。
我正在为列表视图构建快速操作DialogFragment
,并尝试根据android dev guide设置自定义视图。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/white" >
<ImageView
android:id="@+id/quick_action_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="@drawable/windows1" />
<TextView
android:id="@+id/quick_action_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/quick_action_image"
android:layout_toRightOf="@+id/quick_action_image"
android:ellipsize="end"
android:singleLine="true"
android:text="Lilly"
android:textColor="#585858"
android:textSize="16sp" />
<TextView
android:id="@+id/quick_action_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/quick_action_image"
android:layout_toRightOf="@+id/quick_action_image"
android:text="Updated 4 minutes ago"
android:textColor="#a3a3a3"
android:textSize="15sp" />
<ImageButton
android:id="@+id/popup_grid_leave"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_below="@+id/quick_action_activity"
android:layout_margin="20dp"
android:layout_marginTop="30dp"
android:background="@color/transperent"
android:src="@drawable/ic_action_leave" />
<ImageButton
android:id="@+id/popup_grid_silence"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="@+id/popup_grid_leave"
android:layout_alignTop="@+id/popup_grid_leave"
android:layout_centerHorizontal="true"
android:background="@color/transperent"
android:src="@drawable/ic_action_silence" />
<ImageButton
android:id="@+id/popup_grid_mark_as_read"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignBottom="@+id/popup_grid_leave"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/popup_grid_leave"
android:layout_marginRight="15dp"
android:background="@color/transperent"
android:src="@drawable/ic_action_mark_as_read" />
</RelativeLayout>
public class QuickActionFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
View v = LayoutInflater.from(mContext).inflate(
R.layout.view_quick_action, null, false);
// SET ALL THE VIEWS
builder.setTitle(null);
AlertDialog dialog = builder.create();
dialog.setView(v, 0, 0, 0, 0);
// this line didn't change anything
// dialog.getWindow().setBackgroundDrawable(new ColorDrawable(0));
return dialog;
}
}
毕竟,当我运行dialogFragment.show(getSupportedFragmentManager())
时,我仍然会看到图像中所示的黑色边框:
关于如何解决此问题的任何想法?
答案 0 :(得分:10)
尝试以下代码:
public class QuickActionFragment extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog m_dialog = new Dialog(QuickActionFragment.this, R.style.Dialog_No_Border);
LayoutInflater m_inflater = LayoutInflater.from(CustomDialogActivity.this);
View v = LayoutInflater.from(mContext).inflate(R.layout.view_quick_action, null, false);
// SET ALL THE VIEWS
m_dialog.setTitle(null);
m_dialog.setContentView(m_view);
m_dialog.show();
return dialog;
}
}
在Dialog_No_Border
文件中添加res/value/style.xml
样式。
<style name="Dialog_No_Border">
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
此样式会导致在清除
后删除R
答案 1 :(得分:0)
在创建实例时尝试使用setStyle(style,theme)方法,如下所示:
public static YourDialog newInstance() {
YourDialog frag = new YourDialog();
// your code
frag.setStyle(DialogFragment.STYLE_NO_FRAME, 0);
// your code
return frag;
}
我希望这有帮助。
答案 2 :(得分:0)
由于顶部和底部都被截断,我无法获得任何姜饼工作的答案,但我找到了一个解决方法:您可以在顶部和底部设置额外的填充以抵消切割 - 关闭。
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
int padding = getResources().getDimensionPixelSize(R.dimen.your_padding);
view.setPadding(0, padding, 0, padding);
}
然后按照其他答案的规定设置视图
demoDialog.setView(view, 0, 0, 0, 0);
答案 3 :(得分:0)
我无法在Xamarin上获得任何这些工作 - Android。也许这个解决方案可以为那里的人节省一些时间:
public override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetStyle(DialogFragmentStyle.NoFrame, 0);
}
public override void OnResume()
{
base.OnResume();
Dialog.Window.SetBackgroundDrawableResource(Resource.Color.transparent);
}
如果资源中没有“透明”颜色,您可以创建它或使用Android中的默认颜色。我在定制MvvmCross Fingerprint Plugin的对话框片段时遇到了这个问题。