在AlertDialog的元素之间的填充区域中聆听触摸

我有(自定义)标题区域和AlertDialog的消息区域的onTouchListeners。

我正在设置我的对话框,以便用户可以盲目地点击AlertDialog的右上角1/4来切换是否播放背景音乐,因为只需将扬声器作为可点击区域在一个命中箱/区域太小。

我的问题是:标记为红色的消息和标题之间的区域不处理ontouchlistener事件

大多数人会建议创建一个自定义对话框,但事情是我真的喜欢这个对话框看起来的方式(它有一个非常有库存的材料设计审美)并且已经跳过了很多箍,让它看起来完全像我喜欢的方式(在一个看不见的中性按钮上绘制排行榜,自定义标题区域)。 我不想制作自定义对话框,除非我能让它看起来与我现在的完全相同(很难模仿库存材料对话框的外观,相信我,我已经尝试并做了大量的研究/浪费了一个很多时候尝试)。

我假设自定义标题区域和消息区域的触摸事件不包含或说明其间的边距或填充。

请原谅恶心的代码!! 我只是试图将所有东西一起破解并在以后整理它。

提前致谢!

截图

alertdialog的自定义标题区域的线性布局

      

我的android代码

 AlertDialog.Builder ad = new AlertDialog.Builder(new ContextThemeWrapper(AndroidLauncher.this, android.R.style.Theme_Material_Light_Dialog)) .setMessage(msg) .setCustomTitle(myLayout) .setCancelable(false) .setNegativeButton("End Game", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { pauseInterface.end(); dialog.cancel(); } }) .setNeutralButton(" ", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //startSignInIntent(); showLeaderboard(); dialog.cancel(); } }) .setPositiveButton("Resume", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { pauseInterface.resume(); dialog.cancel(); } }); alertDialog = ad.create(); int titleId = getResources().getIdentifier("alertTitle", "id", "android"); if (titleId > 0) { TextView dialogTitle = (TextView) alertDialog.findViewById(titleId); } alertDialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { Button button = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); Drawable drawable = getResources().getDrawable(R.drawable.ic_leaderboard); drawable.setBounds((int) 0, 0, (int) (drawable.getIntrinsicWidth() * 1), drawable.getIntrinsicHeight()); button.setCompoundDrawables(drawable, null, null, null); } }); alertDialog.show(); final ImageView soundToggle = (ImageView) alertDialog.findViewById(R.id.soundtoggle); if (tetrisgame.getMusicState()) { if (tetrisgame.getMusicState()) { soundToggle.setImageDrawable(getResources().getDrawable(R.drawable.music_on, getApplicationContext().getTheme())); } else { soundToggle.setImageDrawable(getResources().getDrawable(R.drawable.music_off, getApplicationContext().getTheme())); } TextView tv = (TextView) alertDialog.findViewById(android.R.id.message); tv.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent m) { if (m.getAction() == MotionEvent.ACTION_DOWN && (m.getX() >= (v.getRight() - (v.getWidth() / 4)))) { Log.println(Log.ERROR, "Ken", "Popular Pothead"); if (tetrisgame.toggleMusic()) { String uri = "@drawable/music_on"; // where myresource (without the extension) is the file int imageResource = getResources().getIdentifier(uri, null, getPackageName()); Drawable res = getResources().getDrawable(imageResource); soundToggle.setImageDrawable(res); // soundToggle.setImageDrawable(getResources().getDrawable(R.drawable.music_off, alertDialog.findViewById(android.R.id.message).getTheme())); } else { soundToggle.setImageDrawable(getResources().getDrawable(R.drawable.music_off, null)); } } return true; } }); final LinearLayout as = (LinearLayout) alertDialog.findViewById(R.id.st); as.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent m) { if (m.getAction() == MotionEvent.ACTION_DOWN) { Log.println(Log.ERROR, "Ken", "Tweed"); if (tetrisgame.toggleMusic()) { String uri = "@drawable/music_on"; // where myresource (without the extension) is the file int imageResource = getResources().getIdentifier(uri, null, getPackageName()); Drawable res = getResources().getDrawable(imageResource); soundToggle.setImageDrawable(res); // soundToggle.setImageDrawable(getResources().getDrawable(R.drawable.music_off, alertDialog.findViewById(android.R.id.message).getTheme())); } else { soundToggle.setImageDrawable(getResources().getDrawable(R.drawable.music_off, null)); } } return true; } });