Android-PickerView 虚拟键与状态栏遮挡的问题

qltillow  于 5个月前  发布在  Android
关注(0)|答案(9)|浏览(83)

虚拟键挡住PickerView,使用.setDecorView((ViewGroup)getWindow().getDecorView().findViewById(android.R.id.content))解决了遮挡的问题,但是状态栏却没有被阴影盖住,请问怎样才能既不让虚拟键挡住PickerView阴影又能够遮住状态栏?

3vpjnl9f

3vpjnl9f1#

@xiaosong520

//将控件添加到decorView中
rootView = (ViewGroup) layoutInflater.inflate(R.layout.layout_basepickerview, mPickerOptions.decorView, false);
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
layoutParams.bottomMargin = 120; //设置一个margin值,可根据底部导航栏的高度设置试试
rootView.setLayoutParams(layoutParams);

daolsyd0

daolsyd02#

同问,怎么解决啊!!!

7xllpg7q

7xllpg7q3#

TimePickerView pvTime = new TimePickerBuilder(context, new OnTimeSelectListener() {
@OverRide
public void onTimeSelect(Date date, View v) {
}
})
.setDecorView(view).build();
pvTime.show();

build之前setDecorView,view传入当前activity/fragment的最底层布局(父布局)

brvekthn

brvekthn4#

/**

  • 设置显示样式为Dialog,以此适配虚拟导航栏遮挡问题,并设置阴影样式
  • (使用.setDecorView((ViewGroup)getWindow().getDecorView().findViewById(android.R.id.content))解决了遮挡的问题,但是状态栏却没有被阴影盖住)
  • @param pvTime
  • @return
    */
    @nonnull
    private static TimePickerView getTimePickerView(TimePickerBuilder pvTime) {
    pvTime.isDialog(true);// 显示为对话框样式
    TimePickerView pickerView = pvTime.build();
    Dialog mDialog = pickerView.getDialog();
    if (mDialog != null) {
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
    ViewGroup.LayoutParams.MATCH_PARENT,
    ViewGroup.LayoutParams.WRAP_CONTENT,
    Gravity.BOTTOM);
    params.leftMargin = 0;
    params.rightMargin = 0;
    pickerView.getDialogContainerLayout().setLayoutParams(params);
    Window dialogWindow = mDialog.getWindow();
    if (dialogWindow != null) {
    dialogWindow.setWindowAnimations(R.style.picker_view_slide_anim);//修改动画样式
    dialogWindow.setGravity(Gravity.BOTTOM);//改成Bottom,底部显示
    dialogWindow.setDimAmount(0.3f);// 设置透明度
    }
    }
    return pickerView;
    }

通过上面方法将其设置为dialog样式,然后显示即可解决
TimePickerView pickerView = getTimePickerView(pvTime);
pickerView.show();

7xzttuei

7xzttuei5#

build()之前调用setDecorView即可
activity中如下

.setDecorView(activity.getWindow().getDecorView().findViewById(android.R.id.content))
                .build();

Frament中类似 下面是demo中的例子:

public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_test, null);
        return mView;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mFrameLayout = (FrameLayout) mView.findViewById(R.id.fragmen_fragment);
    }

 .setDecorView(mFrameLayout)//非dialog模式下,设置ViewGroup, pickerView将会添加到这个ViewGroup中
jvidinwx

jvidinwx6#

@keke195 可尝试使用dialog方式。

qkf9rpyu

qkf9rpyu7#

dialog也没用啊,这要怎么解决。。

bxfogqkk

bxfogqkk9#

有什么办法解决吗

相关问题