如何更改新TabLayout上所选选项卡下划线的颜色?该PagerTabStrip有一个方法setTabIndicatorColor(int color),TabLayout似乎不具有这样的方法.

当我们有一个EditText并且它失去焦点(对于不需要键盘的元素)时,软键盘应该自动隐藏还是我们应该自己隐藏它?
我正在将焦点从AutoCompleteSearchView(EditText我的行为应该像我猜的那样)移动到a Button,requestFocus()返回true,但键盘不会隐藏.
考虑一个将接口实现作为参数的函数,如下所示:
interface Callback {
fun done()
}
class SomeClass {
fun doSomeThing(callback: Callback) {
// do something
callback.done()
}
}
Run Code Online (Sandbox Code Playgroud)
当我想测试这个函数的调用者时,我可以做类似的事情
val captor = ArgumentCaptor.forClass(Callback::class)
Mockito.verify(someClass).doSomeThing(captor.capture())
Run Code Online (Sandbox Code Playgroud)
为了测试调用回调时其他类的作用,我可以这样做
captor.value.done()
Run Code Online (Sandbox Code Playgroud)
问题:如果我用高阶函数替换回调接口,我该怎么做呢?
fun doSomeThing(done: () -> Unit) {
// do something
done.invoke()
}
Run Code Online (Sandbox Code Playgroud)
这可以用ArgumentCaptor来完成,我必须使用哪个类 ArgumentCaptor.forClass(???)
我在Dagger 2网站上看到了以下示例:
class Thermosiphon implements Pump {
private final Heater heater;
@Inject
Thermosiphon(Heater heater) {
this.heater = heater;
}
...
}
Run Code Online (Sandbox Code Playgroud)
和文件:
当请求新实例时,Dagger将获取所需的参数值并调用此构造函数.
当我写一个模块来提供Thermosiphon类似的
@Module
public class ThermosiphonModule {
@Provides
@Singleton
Thermosiphon provideThermosiphon() {
return new Thermosiphon(???);
}
}
Run Code Online (Sandbox Code Playgroud)
该Thermosiphon构造仍然需要Heater作为一个参数,渲染无用整个"的构造的依赖关系自动注射".
我试过了
return new Thermosiphon(null);
Run Code Online (Sandbox Code Playgroud)
和
return new Thermosiphon();
Run Code Online (Sandbox Code Playgroud)
(空构造函数)并希望Dagger2拿起我希望Heater注入的缺失,但所提供的加热器Thermosiphon总是为空;
我验证虽然我的HeaterComponent/ HeaterModule工作正常,并能提供Heater.
我是否完全误解了'Dagger满足你的构造函数依赖关系'的整个特征,还是我错过了什么?
考虑以下课程:
public class Cars extends Observable{
private ArrayList<String> carList = new ArrayList<String>();
public void addToCarList(String car){
// ...
hasChanged();
notifyObservers();
}
public void removeFromCarList(String car){
// ...
hasChanged();
notifyObservers();
}
public ArrayList<String> getCarList() {
return carList;
}
}
Run Code Online (Sandbox Code Playgroud)
如您所见,每次更改carList时,我都要通知Observers.如果有人这样做getCarList().add(...);,这就被规避了.
我如何提供carList对它的读访问权(用于迭代它等),但是除了特殊方法addToCarList和removeFromCarList?之外,它阻止对它的写访问 ?
我想到了这个:
public ArrayList<String> getCarList() {
return (ArrayList<String>)carList.clone();
}
Run Code Online (Sandbox Code Playgroud)
但是有人使用我的课程,在向克隆添加一些内容时carList,不会被告知这不是它的意图.
我有以下布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="@android:style/Widget.Material.ProgressBar.Large"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我有一个Android 5.0.1不显示的Nexus 5运行ProgressBar,显然是因为风格.当我将样式设置为例如
style="@android:style/Widget.ProgressBar.Large"
Run Code Online (Sandbox Code Playgroud)
要么
style="@android:style/Widget.Holo.ProgressBar.Large"
Run Code Online (Sandbox Code Playgroud)
它显示.我有一个相同的Nexus 5也运行Android 5.0.1,显示所有ProgressBar的罚款.在开发人员选项中启用"绘制布局边框"选项,它显示它ProgressBar包含在布局中,它根本不显示.
这看起来很奇怪,有什么想法可以在这里发生什么?

android android-layout android-progressbar android-5.0-lollipop
在Android Studio/Gradle Android项目中,我有两个构建变体,Debug和Release(标准项目设置).
你可以在这张图片中看到我的文件夹结构:

我有一个WebView,它应该显示/ res/raw-folder中的imprint.html.WebView说,这适用于发布版本,但不适用于调试版本
Couldn't load website under 'file///android_res/raw/imprint.hml
net::EE_FILE_NOT_FOUND
Run Code Online (Sandbox Code Playgroud)
这让我很困惑.
我究竟做错了什么?
我使用Android Studio 1.1.0的新单元测试支持功能运行了一些旧的测试.运行gradlew testDebug时,运行测试,但所有需要Context失败的测试都因为getContext(AndroidTestCase)/ getInstrumentation.getContext()(InstrumentationTestCase)都返回null.
我怎么解决这个问题?
这是我试过的两个变种:
import android.content.Context;
import android.test.InstrumentationTestCase;
public class TestTest extends InstrumentationTestCase {
Context context;
public void setUp() throws Exception {
super.setUp();
context = getInstrumentation().getContext();
assertNotNull(context);
}
public void testSomething() {
assertEquals(false, true);
}
}
Run Code Online (Sandbox Code Playgroud)
和
import android.content.Context;
import android.test.AndroidTestCase;
public class TestTest extends AndroidTestCase {
Context context;
public void setUp() throws Exception {
super.setUp();
context = getContext();
assertNotNull(context);
}
public void testSomething() {
assertEquals(false, true);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的模块build.gradle:
apply plugin: …Run Code Online (Sandbox Code Playgroud) 我有一个带有一些项目(字符串)的微调器.我想将所选项目添加到列表中.我在网上看到我应该使用onItemSelectedListener而不是onItemClickListener.
我实现了这个,但我不知道如何完成将其添加到列表中的步骤.
class NewKitListActivity : AppCompatActivity() {
var spinnerArray = arrayOf("Dumbell", "Punching Bag", "Yoga Ball", "Skipping Rope")
//var spinnerArray = arrayOf(DataService.kitList)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_new_kit_list)
val spinner = newKitItemSpinner
val spinnerArrayAdapter = ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, spinnerArray)
//selected item will look like a spinner set from XML
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = spinnerArrayAdapter
spinner.onItemSelectedListener = object : OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
val selectedItem = parent.getItemAtPosition(position).toString()
if (selectedItem == …Run Code Online (Sandbox Code Playgroud) 我在我的应用程序清单中注册了以下intent过滤器:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="m.mycompany.de"
android:pathPattern="/app/list"
android:scheme="http" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)
并创建了一个简单的html页面来测试应用程序是否正确打开:
<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>
A Small Hello
</TITLE>
</HEAD>
<BODY>
<a href = "http://m.mycompany.de/app/list?param1=178¶m2=87294">Click</a>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)
在某些设备上(例如运行Android 5.1的Nexus 5)点击链接按预期打开我的应用程序,在其他设备上(例如Nexus 6也运行5.1)PlayStore(我的应用程序页面)打开而不是我的应用程序.
任何想法可能是什么问题?
编辑:奇怪的是,当将URL简化为以下时,这个"错误"已经消失:
http://m.mycompany.de/list?param1=178¶m2=87294
Run Code Online (Sandbox Code Playgroud)
我的意图过滤到
<data
android:host="m.mycompany.de"
android:pathPattern="/app"
android:scheme="http" />
Run Code Online (Sandbox Code Playgroud)
这不是一个选项,因为我无法控制我的实时应用程序的URL.