gpt4 book ai didi

android - 从 Bottom Sheet 对话框调用警报对话框或另一个 Bottom Sheet 会导致背景闪烁

转载 作者:行者123 更新时间:2023-12-03 10:12:18 35 4
gpt4 key购买 nike

https://imgur.com/gallery/xntpREw

有没有人遇到这个问题,或者我做错了什么

更新:我在android 8和9版本上测试了同一个应用程序,但没有出现此故障,因此,这可能特定于android版本10

编辑:

这是对话框片段类,其中在itemview click-上调用警报对话框

public class ItemListDialogFragment extends BottomSheetDialogFragment 
{
private static final String ARG_ITEM_COUNT = "item_count";

public static ItemListDialogFragment newInstance(int itemCount)
{
final ItemListDialogFragment fragment =
new ItemListDialogFragment();

final Bundle args = new Bundle();
args.putInt(ARG_ITEM_COUNT, itemCount);

fragment.setArguments(args);

return fragment;
}

@Nullable
@Override
public View onCreateView(
LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState)
{
return inflater.inflate(
R.layout.
fragment_item_list_dialog_list_dialog,
container,
false );
}

@Override
public void onViewCreated(
@NonNull View view,
@Nullable Bundle savedInstanceState )
{
final RecyclerView recyclerView =
(RecyclerView) view;
recyclerView.setLayoutManager(
new LinearLayoutManager( getContext() ) );

recyclerView.setAdapter(
new ItemAdapter( getArguments().getInt( ARG_ITEM_COUNT ) ) );

recyclerView.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick(View view)
{
alert();
}
} );
}

private class ViewHolder extends RecyclerView.ViewHolder
{
final TextView text;

ViewHolder(
LayoutInflater inflater,
ViewGroup parent )
{
// TODO: Customize the item layout
super(
inflater.inflate(
R.layout.
fragment_item_list_dialog_list_dialog_item,
parent,
false ) );

text = itemView.findViewById(R.id.text);

itemView.setOnClickListener(
new View.OnClickListener()
{
@Override
public void onClick( View view )
{
alert();
}
} );
}
}

private class ItemAdapter extends RecyclerView.Adapter<ViewHolder>
{
private final int mItemCount;
ItemAdapter( int itemCount )
{
mItemCount = itemCount;
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(
@NonNull ViewGroup parent,
int viewType)
{
return new ViewHolder(
LayoutInflater.from( parent.getContext( ) ),
parent );
}

@Override
public void onBindViewHolder( ViewHolder holder, int position )
{
holder.text.setText( String.valueOf( position ) );
}

@Override
public int getItemCount()
{
return mItemCount;
}
}

private void alert()
{
AlertDialog.Builder builder =
new AlertDialog.Builder( getActivity() );

builder.setTitle( "Alert dialog" );
builder.setMessage( "This is a alert dialog" );
builder.setPositiveButton(
"ok",
new DialogInterface.OnClickListener()
{
@Override
public void onClick( DialogInterface dialogInterface, int i )
{
}
} );
builder.setNegativeButton(
"close",
new DialogInterface.OnClickListener()
{
@Override
public void onClick( DialogInterface dialogInterface, int i )
{
}
} );

builder.show();
}

这就是 Bottom Sheet 的称呼-
public class MainActivity extends AppCompatActivity 
{

@Override
protected void onCreate( Bundle savedInstanceState )
{
super.onCreate( savedInstanceState );
setContentView( R.layout.activity_main );

ItemListDialogFragment.
newInstance(10).
show( getSupportFragmentManager(), "df" );
}
}

最佳答案

我可以通过在设置嵌套对话框的主题时将android:backgroundDimEnabled设置为false来找到解决方法。

<style name="Theme.MyApp.BottomSheetDialog.Nested" parent="@style/Theme.Design.Light.BottomSheetDialog">
<item name="android:backgroundDimEnabled">false</item>
</style>
在我的 onCreateDialog里面:
 val bottomSheet =
if (isNested()) {
BottomSheetDialog(
requireContext(),
R.style.Theme_MyApp_BottomSheetDialog_Nested
)
} else {
BottomSheetDialog(
requireContext(),
R.style.Theme_Design_BottomSheetDialog
)
}
将主题传递给 AlertDialog.Builder时,它应该起作用。

关于android - 从 Bottom Sheet 对话框调用警报对话框或另一个 Bottom Sheet 会导致背景闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60691007/

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