我有一个从片段调用的PopupWindow,除了我的Spinner,一切都有效.当我点击我的Spinner时它会崩溃并给出错误:
"android.view.WindowManager $ BadTokenException:无法添加窗口 - 令牌android.view.ViewRootImpl$W@421a46d8无效;您的活动是否在运行?"
我的代码调用片段中的弹出窗口:
ManagerPopUp mManagerPopUp = new ManagerPopUp(getActivity());
mManagerPopUp.showPopUpAddEvent();
Run Code Online (Sandbox Code Playgroud)
我在ManagerPopUp中的代码显示Popup:
public class ManagerPopUp {
private static final String TAG = "PopUpManager";
private Context mContext;
public ManagerPopUp(Context mContext){
this.mContext = mContext;
}
public PopupWindow showPopUpAddEvent(){
final PopupWindow popUp = new PopupWindow(mContext);
LayoutInflater inflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.popup_add_event, null);
//Code for popup event
TextView txtRoom, txtTitle, txtEnd, txtStart;
ToggleButton tgRepeateWeekly, tgAddReminder;
Button btConfirme, btCancel;
txtTitle = (TextView)layout.findViewById(R.id.txt_lesson_title_event);
txtRoom = (TextView)layout.findViewById(R.id.txt_lesson_room_event);
txtStart = (TextView)layout.findViewById(R.id.txt_lesson_start_hour_event);
txtEnd = (TextView)layout.findViewById(R.id.txt_lesson_end_hour_event); …Run Code Online (Sandbox Code Playgroud) android android-adapter android-fragments android-spinner android-popupwindow
我想在单击按钮时显示扩展 Fragment 的 PlaceHodler 类中的弹出窗口。为了进行测试,我编写了这段确实有效的代码,但我想这很荒谬(使用 Button 对象作为父视图等等......我找不到另一种方法来使其工作......)。请查看这段代码并建议我如何改进它。请不要评判我,因为我是编程的初学者。
我的代码:
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
final Button button1 = (Button)rootView.findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
Log.i("ilog", "onClick() works");
PopupWindow pw = new PopupWindow(getActivity());
TextView tv = new TextView(getActivity());
LayoutParams linearparams1 = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
tv.setLayoutParams(linearparams1);
tv.setText("Testing");
pw.setContentView(tv);
pw.setWidth(400);
pw.setHeight(180);
pw.showAtLocation(button1, Gravity.CENTER_HORIZONTAL, 25, 25);
pw.update();
}
}); …Run Code Online (Sandbox Code Playgroud) android placeholder android-fragments android-view android-popupwindow
我创建了自己的android下拉列表(微调器).它通过使用popupWindow(...)定制.现在我想相应地设计它.我想应用与微调器下拉相同的样式,甚至是另一种下拉样式.我特别需要渲染本机微调器后出现的阴影效果和阴影.
任何人都知道我可以应用的风格,而不构建我自己的阴影,可能与本机集不一样?
我已经创建了更改弹出菜单背景颜色的样式,现在我还需要知道如何更改菜单项文本颜色。以下是我使用的样式
<style name="AppTheme" parent="android:Theme.Holo">
<item name="android:popupMenuStyle">@style/PopupMenu</item>
</style>
<style name="PopupMenu" parent="@android:style/Widget.PopupMenu">
<item name="android:popupBackground">@color/popup_menu_bg_color</item>
</style>
Run Code Online (Sandbox Code Playgroud) 下面是我的代码,菜单-ImageView menubottom-ImageView我的要求是在显示弹出窗口时显示menubottom图像。
menu.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{View layout=(View)getLayoutInflater().inflate(R.layout.navigationbar, null);
popupWindow = new PopupWindow(getApplicationContext());
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setContentView(layout);
popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(swidth);
popupWindow.setFocusable(false);
popupWindow.setOutsideTouchable(true);
popupWindow.setAnimationStyle(-1);
if(x==1)
{ popupWindow.showAsDropDown(menubottom);
menubottom.setVisibility(View.VISIBLE);
x=0;
}
else
{
popupWindow.dismiss();
popupWindow=null;
}
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
// TODO Auto-generated method stub
menubottom.setVisibility(View.INVISIBLE);
x=1;
}
});
}
}
Run Code Online (Sandbox Code Playgroud)
问题:单击菜单按钮时,将显示弹出窗口,并显示菜单底部。再次按菜单,弹出菜单将被隐藏,然后再次显示。
在弹出菜单外按时,其按预期方式工作(弹出和菜单底部被隐藏)
我认为,setOnDismissListener再次触发menu.setOnClickListener。提前致谢。
我已进入/退出动画风格为PopupWindow这样的
mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
Run Code Online (Sandbox Code Playgroud)
和风格一样
<style name="PopupAnimation" parent="Widget.AppCompat.PopupWindow">
<item name="android:windowEnterAnimation">@anim/popup_show</item>
<item name="android:windowExitAnimation">@anim/popup_hide</item>
</style>
Run Code Online (Sandbox Code Playgroud)
因此,当PopupWindow显示/隐藏时,它具有适用于Lollipop以及所有以前的Android版本的动画.但随着Marshmallow动画时间间隔后弹出窗口显示并且没有动画效果.
动画/弹出窗口show.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.0"
android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000"/>
</set>
Run Code Online (Sandbox Code Playgroud)
动画/弹出窗口hide.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="1.0"
android:toAlpha="0"
android:interpolator="@android:anim/accelerate_interpolator"
android:duration="1000"/>
</set>
Run Code Online (Sandbox Code Playgroud) android android-animation android-popupwindow android-6.0-marshmallow
看了很多类似的问题但没有运气......
我正在尝试找到使用媒体控制器播放视频的正确方法(半屏窗口,需要时也可以全屏)。视频应该漂浮在本机控件之上,视频和本机控件都可以接收触摸事件(都是可点击的。就像 Facebook Messenger 图标)。
现在我正在做的事情:我启动一个透明的活动,并在 a 中播放视频,VideoView并将其布局参数和活动的布局参数设置为占据屏幕的一半。另一半是本机屏幕。我将窗口设置为:
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY)
这样做的作用是,我可以看到正在播放的视频,VideoView 但无法触摸和使用其媒体控制器(播放、暂停等),但我可以看到可以触摸的本机屏幕!
我尝试了不同的标志来启用媒体控制器,但随后VideoView完全消耗触摸事件。这意味着现在我无法触摸它后面的本机屏幕的一半。
本机屏幕顶部的 VideoView - 两者都可以处理触摸事件, 我认为可能使用对话框或弹出窗口,但找不到说对话框可以接收触摸事件而本机屏幕也可以接收触摸事件的内容。
视频应该始终位于最上面。提前致谢 !:)
android android-dialog android-windowmanager android-videoview android-popupwindow
我有popup window自定义布局,其中有edittext. 我正在尝试显示错误消息edittextwithsetError方法中显示错误消息,但它给出了以下异常。
android.view.WindowManager$BadTokenException: Unable to add window -- token android.view.ViewRootImpl$W@211ffd68 is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:579)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:282)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85)
at android.widget.PopupWindow.invokePopup(PopupWindow.java:1104)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:1008)
at android.widget.PopupWindow.showAsDropDown(PopupWindow.java:968)
at android.widget.Editor.showError(Editor.java:334)
at android.widget.Editor.setError(Editor.java:355)
at android.widget.TextView.setError(TextView.java:4654)
at android.widget.TextView.setError(TextView.java:4639)
at com.ebusiness.worldofjobs.helpers.HelperEditText.isEmailValid(HelperEditText.java:38)
at com.ebusiness.worldofjobs.activities.LoginActivity$4$2.onClick(LoginActivity.java:149)
at android.view.View.performClick(View.java:4785)
at android.view.View$PerformClick.run(View.java:19884)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5343)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
Run Code Online (Sandbox Code Playgroud)
弹出窗口:
View popupView = LayoutInflater.from(LoginActivity.this).inflate(R.layout.popup_reset_password, null);
EdiText etSmaple = …Run Code Online (Sandbox Code Playgroud) 我可以使用PopupWindow而不是Dialog来调暗背景吗?我问这个是因为我正在使用Dialogs,但Dialog没有显示在点击的项目下面,并且PopupWindow我已经在项目下面显示了弹出窗口.
android dialog popupwindow android-dialog android-popupwindow
我PopupMenu在我的应用程序中使用了几个s,它们都按预期工作
但是我希望将白色线条分开,但我无法找到我想要设置的位置.我希望我可以访问底层的ListView,但这似乎不可能.我也看不到与分隔线相关的样式项.
这可能吗,我应该在哪里/如何设置?
customization android divider android-layout android-popupwindow
android ×10
android-menu ×2
android-view ×1
dialog ×1
divider ×1
placeholder ×1
popupwindow ×1
styles ×1