gpt4 book ai didi

android - DialogFragment去除黑边

转载 作者:太空宇宙 更新时间:2023-11-03 11:51:07 26 4
gpt4 key购买 nike

我看到了this question还有this one和其他一些人,但没有任何真正帮助我。

我正在为我的 ListView 构建一个快速操作 DialogFragment 并尝试根据 android dev guide 为其设置自定义 View .

view_quick_action.xml

<?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>

QuickActionFragment.java

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()) 时,我仍然得到如图所示的黑色边框: quickActionImage

关于如何解决这个问题有什么想法吗?

最佳答案

试试下面的代码:

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;
}
}

res/value/style.xml 文件中添加 Dialog_No_Border 样式。

<style name="Dialog_No_Border">
<item name="android:windowIsFloating">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>

此样式导致 R 在清理后被删除

关于android - DialogFragment去除黑边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14746766/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com