@Override
public void onClick(View v) {
switch (v.getId())
{
case R.id.legalInformationLL:
startActivity(new Intent(AboutActivity.this, LegalInformation.class));
break;
case R.id.backIB:
finish();
break;
}
}
Run Code Online (Sandbox Code Playgroud)
对于此代码“资源 ID 在 Android Gradle 插件版本 5.0 中将是非最终的,请避免在 switch case 语句中使用它们”警告出现。可能的解决方案是什么?如果我将此代码更改为:
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.legalInformationLL) {
startActivity(new Intent(AboutActivity.this, LegalInformation.class));
} else if (id == R.id.backIB) {
finish();
}
}
Run Code Online (Sandbox Code Playgroud)
警告消失;但与 if 语句相比,switch 语句的性能更好。那么有什么可能的解决方案可以更快地有效工作呢?
如果我们 在 android 上的 chrome 浏览器中启用chrome://flags/#enable-force-dark标志,则网页会变暗。
我想在 android webview 中实现类似的东西(即暗网 ui)。
目前我正在使用以下代码:
private void injectCSS() {
String code = "javascript:(function() {" +
"var node = document.createElement('style');"+
"node.type = 'text/css';"+
" node.innerHTML = 'body, label,th,p,a, td, tr,li,ul,span,table,h1,h2,h3,h4,h5,h6,h7,div,small {"+
" color: #deFFFFFF;"+
"background-color: #232323;"+
" } ';"+
" document.head.appendChild(node);})();";
webView.evaluateJavascript(code,null);
}
Run Code Online (Sandbox Code Playgroud)
我在以下位置运行此代码:
@Override
public void onProgressChanged(WebView view, final int
newProgress) {
super.onProgressChanged(view, newProgress);
injectCSS();
}
@Override
public void onPageStarted(final WebView view, String url,
Bitmap favicon) {
injectCSS();
super.onPageStarted(view, url, favicon); …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
public RVIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
TypedArray attributes = context.obtainStyledAttributes(
attrs, R.styleable.RVIndicator, defStyleAttr, R.style.RVIndicator);
dotColor = attributes.getColor(R.styleable.RVIndicator_dotColor, 0);
selectedDotColor = attributes.getColor(R.styleable.RVIndicator_dotSelectedColor, dotColor);
dotNormalSize = attributes.getDimensionPixelSize(R.styleable.RVIndicator_dotSize, 0);
spaceBetweenDotCenters = attributes.getDimensionPixelSize(R.styleable.RVIndicator_dotSpacing, 0) + dotNormalSize;
looped = attributes.getBoolean(R.styleable.RVIndicator_looped, false);
int visibleDotCount = attributes.getInt(R.styleable.RVIndicator_visibleDotCount, 0);
setVisibleDotCount(visibleDotCount);
visibleDotThreshold = 0;
attributes.recycle();
paint = new Paint();
paint.setAntiAlias(true);
if (isInEditMode()) {
setDotCount(visibleDotCount);
onPageScrolled(visibleDotCount / 2, 0);
}
}
Run Code Online (Sandbox Code Playgroud)
对于以下语句 lint 给出警告“TypedArray”在没有“try”-with-resources 语句的情况下使用”。如何解决这个警告?
TypedArray attributes = context.obtainStyledAttributes(
attrs, R.styleable.RVIndicator, defStyleAttr, R.style.RVIndicator);
Run Code Online (Sandbox Code Playgroud) 我正在使用类似的动作芯片:
<com.google.android.material.chip.Chip
android:id="@+id/copyLinkChip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/copy_link"
app:chipIcon="@drawable/content_copy_background"
app:chipIconTint="?attr/primaryText"
android:textColor="?attr/primaryText"
app:chipStrokeWidth="0.5dp"
/>
Run Code Online (Sandbox Code Playgroud)
我想让它的背景完全透明如何制作呢?
警告说: 此文件夹配置('v24')是不必要的;'minSdkVersion' 为 24。将这个文件夹中的所有资源合并到 'drawable-anydpi' 中。
当我将 drawable-anydpi-v24 重命名为 drawable-anydpi 时,它说资源与另一个资源文件发生冲突(png 与 xml 发生冲突)。也就是说,存在一个扩展名为 .xml 的相同资源文件。
请注意,在 drawable-anydpi-v24 中有 png 通知图标文件。
而且也没有任何名称为 drawable-anydpi 的文件夹。所以我将 drawable-anydpi-v24 重命名为 drawable-anydpi。
我当前的项目有这个可绘制文件夹: drawable、drawable-anydpi-v24、drawable-hdpi、drawable-mdpi、drawable-nodpi、drawable-v24、drawable-xhdpi、drawable-xxhdpi、drawable-xxxhdpi
那么,就我而言,如何摆脱这个警告?