jjzjj

android - Android 中的 Button Click 上的 Long Click 事件触发

听说在Android中我们可以通过按住几秒钟来创建Button的点击事件。我想在我的应用程序中使用该功能。谁能告诉我该怎么做?谢谢,大卫 最佳答案 查看View.OnLongClickListener。publicclassMyActivityextendsActivity{protectedvoidonCreate(Bundleicicle){super.onCreate(icicle);setContentView(R.layout.content_layout_id);finalButtonbutton=(Button)fin

android - 如何在 list 中注册 *inner* MEDIA_BUTTON BroadcastReceiver?

我managed让我的耳机按钮在按下时被我的应用程序识别,但其中一个按钮需要调用MyCustomActivity中的方法。问题是onReceive的第一个参数是无法转换为Activity的上下文,因此我不得不将BroadcastReceiver实现为MyCustomActivity中的内部类。到目前为止一切顺利,但如何在list中注册这个内部MediaButtonEventReceiver?对于独立类来说,这很简单:对MyCustomActivity的mReceiver执行相同操作的技巧/语法是什么?privateBroadcastReceivermReceiver=newBroadc

android - 我可以通过在它们之间切换来使用两个 Button 的一个定义吗?

我有这两个ImageButtonViewredButton和blueButton但在代码中我只使用了一个定义ImageButtonGButton=(ImageButton)findViewById(R.id.blueButton);然后在clickListener中我有这段代码:GButton.setOnClickListener(newImageButton.OnClickListener(){publicvoidonClick(Viewv){switch(v.getId()){case(R.id.blueButton):GButton=(ImageButton)findViewBy

java - 按 "back button"退出后 Android 应用程序崩溃

作为我的android应用程序开发研究的一部分,我通过访问LED闪光灯开发了一个简单的SOS应用程序。一切正常,LED以1/2秒的间隔闪烁。但是当用户按下手机中的后退按钮时,应用程序会退出,并在1/2秒后出现“崩溃/强制关闭”消息。我是Android开发的新手,我的代码有什么问题?privatebooleanlOn=true;TimermTimer=newTimer();TimerTaskmTimerTask=newTimerTask(){@Overridepublicvoidrun(){if(lOn){finalParametersp=camera.getParameters();L

android - 如何创建类似 AppCompat AlertDialog Button 的按钮?

我想覆盖系统窗口。我正在尝试创建类似AppCompat样式的按钮。我试过这个:XML:服务:LayoutInflaterinflater;publicvoidsetTheme(inttheme){ContextThemeWrappercontextThemeWrapper=newContextThemeWrapper(this,theme);inflater=LayoutInflater.from(this).cloneInContext(contextThemeWrapper);}publicvoidonCreate(){booleanthemeDark=getThemeDark()

java - 如果我按一次耳机按钮,android.intent.action.MEDIA_BUTTON 事件会触发两次

我已经编写了一段代码来在按下耳机媒体按钮时显示Toast。我使用了Intent过滤器来完成它。但问题是当我按下媒体按钮时它会触发两次。我的代码是:MainActivity.javaprivateMusicIntentReceivermyReceiver;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);myReceiver=newMusicIntentReceiver();((

android - FABM : Floating Action Button Menu

我有float操作菜单,我使用这个库来制作它'com.github.clans:fab:1.6.1'现在我需要在点击时更改我的图标它。我有一些图标,当我点击菜单时,我需要将它转换为另一个图标(图标加号)。可能吗?这是我的xml:一开始图标是ic_float_cards,但点击后应该是ic_float_cross如果你有什么想法请告诉我) 最佳答案 这完成了工作,并且还将恢复为原始图标。finalFloatingActionMenufab=(FloatingActionMenu)findViewById(R.id.menu3);fab

android - 修改 Button 时 onResume 出现 NullPointerException,为什么?

我从我的一些用户那里得到了一个NullPointerException,我无法发现问题是什么,它被抛到这一行:((Button)findViewById(R.id.speakEnglishButton)).setText("");我看不出有什么问题,按钮与那个ID一起存在,它编译正常,在我的模拟器和2台设备上工作正常,但是我的开发者控制台中发布了大约100个左右的错误此版本的用户。仔细观察onResume:@OverrideprotectedvoidonResume(){super.onResume();SharedPreferencessp=PreferenceManager.get

java - 安卓 : overriding Button minheight programmatically

在搜索如何减少按钮内的填充时,我在https://stackoverflow.com/a/20323723/3888000中找到了答案我应该在xml文件中将按钮的最小高度设置为0dp。是的,它对我有用。问题是:我想以编程方式创建我的按钮,但setMinimumHeight(1)和setMinHeight(1)都不起作用。怎么做?顺便问一下,这两种方法有什么区别?谢谢! 最佳答案 只是打电话btn.setMinHeight(0);或btn.setMinimumHeight(0);对我不起作用。当我调用这两种方法时它起作用了,就像那样:

android - 我想在使用 kotlin 在 android 中单击 Button 后更改背景

我想在点击按钮后改变背景varbm:Button=messegbm.setOnClickListener{bm.background=R.color.green}错误日志:Error:(35,31)Typemismatch:inferredtypeisIntbutDrawable!wasexpectedError:Executionfailedfortask':app:compileDebugKotlin'.Compilationerror.Seelogformoredetails 最佳答案 background需要一个Drawab