jjzjj

programmatical

全部标签

android - 如何设置应用程序的 ImageButton 属性 :srcCompat ="@drawable/pic" programmatically?

如何设置的ImageButton属性app:srcCompat="@drawable/pic"以编程方式?类似于myImageButton.setBackgroundResource(R.drawable.eng2);但app:srcCompat的属性。 最佳答案 您需要使用setImageResource()方法。imageButton.setImageResource(R.drawable.eng2); 关于android-如何设置应用程序的ImageButton属性:srcComp

android - 如何设置应用程序 :layout_scrollFlags for Toolbar programmatically

我的应用有一个viewpager和4个标签,每个标签都有很多fragment。但我只想让我的工具栏在2个特定选项卡中滚动recyclerview时向上/向下滚动。但我不知道如何阻止其他选项卡的工具栏滚动。我试图为每个fragment导入工具栏,但似乎我做不到。有人有解决这个问题的想法吗? 最佳答案 我强烈建议不要根据选择的选项卡更改滚动标志-滚动到非回收站View选项卡时让工具栏自动返回(并且内容向下移动)可能非常不和谐,可能不是交互模式您想要的(如果您的两个RecyclerView选项卡彼此相邻,您会很生气)。不过,如果你想亲眼看

javascript - Mocha : create and finalize test programmatically

我想实时代理在其他环境中运行的测试结果。下面是一些我想要实现的伪代码:vartest=proxy.getCurrentTest();//=>{slow:200,timeout:2000,duration:235,result:'error'};vartmpIt=it('test1',function(){this.slow(test.slow);this.timeout(test.timeout);});tmpIt.close({duration:test.duration,result:test.result});//thisshouldmakethistestredintheout

Python 库 'unittest' : Generate multiple tests programmatically

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Howdoyougeneratedynamic(parameterized)unittestsinPython?我有一个要测试的函数,under_test,以及一组预期的输入/输出对:[(2,332),(234,99213),(9,3),#...]我希望这些输入/输出对中的每一对都在其自己的test_*方法中进行测试。这可能吗?这是我想要的,但强制每个输入/输出对进入一个测试:classTestPreReqs(unittest.TestCase):defsetUp(self):self.expected_pa

java - 安卓 : How to set MediaPlayer volume programmatically?

如何以编程方式设置媒体播放器音量。我将它用于警报通知。任何帮助都非常感谢,并提前感谢。 最佳答案 使用AudioManager,您可以简单地控制媒体播放器的音量。AudioManageraudioManager=(AudioManager)getSystemService(Context.AUDIO_SERVICE);audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,20,0);也来自MediaPlayer(但我没有尝试过)setVolume(floatleftVolume

android - 约束布局 : change constraints programmatically

我需要ConstraintSet方面的帮助。我的目标是在代码中更改View的约束,但我不知道如何正确地做到这一点。我有4个TextView和一个ImageView。我需要将ImageView约束设置为TextView之一。check_answer4=(TextView)findViewById(R.id.check_answer4);check_answer1=(TextView)findViewById(R.id.check_answer1);check_answer2=(TextView)findViewById(R.id.check_answer2);check_answer3=

安卓 : How to update the selector(StateListDrawable) programmatically

我想以编程方式更新按钮的选择器。我可以使用下面给出的xml文件来做到这一点我想以编程方式做同样的事情。我已经尝试过下面给出的方法privateStateListDrawablesetImageButtonState(intindex){StateListDrawablestates=newStateListDrawable();states.addState(newint[]{android.R.attr.stateNotNeeded},R.drawable.btn_off);states.addState(newint[]{android.R.attr.state_pressed,a

android - 设置安卓:animateLayoutChanges programmatically

我正在以编程方式创建线性布局,并希望它们在可见性设置为可见/消失时淡入和淡出。我可以设置android:animateLayoutChanges="true"在xml文件中,但由于我是以编程方式创建View,因此我需要以编程方式设置它。我该怎么做? 最佳答案 使用此代码:container.setLayoutTransition(newLayoutTransition());或LayoutTransitionlt=newLayoutTransition();lt.disableTransitionType(LayoutTransit

安卓文本字段 : set focus + soft input programmatically

在我看来,我有一个搜索EditText,我想以编程方式触发该字段上单击事件的行为,即,将焦点放在文本字段上并在必要时显示软键盘(如果没有可用的硬键盘)。我试过field.requestFocus()。该字段实际上获得了焦点,但未显示软键盘。我试过field.performClick()。但这只会调用该字段的OnClickListener。有什么想法吗? 最佳答案 好先生,试试这个:edittext.setFocusableInTouchMode(true);edittext.requestFocus();我不确定,但某些手机(某些旧

iOS 7/Xcode 5 : Access device launch images programmatically

有没有什么方法可以在通用iOS应用中使用应用LaunchImage作为背景,而无需将相同的图像资源放在多个位置?我无法访问Images.xcassets中的LaunchImage文件,因此我创建了两个新的图像集“背景肖像”和“背景风景”(因为似乎没有办法将横向和纵向图像放在同一个集合中)。虽然这种解决方法可以解决问题,但我不希望将每个图像都包含到应用程序中两次。这也有很高的维护成本。感谢任何有关如何访问当前设备的LaunchImage的建议。GCOLaunchImageTransition必须为iOS 最佳答案 您可以复制/粘贴以下