我正在制作一个导航抽屉,其中图标根据文本的颜色着色.
这是我在res/drawable中声明的选择器
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:color="@color/emerald"/>
<item android:state_selected="true" android:color="@color/emerald"/>
<item android:state_pressed="true" android:color="@color/emerald"/>
<item android:color="@android:color/white"/>
</selector>
Run Code Online (Sandbox Code Playgroud)
这是我的ViewHolder
Drawable drawable = ContextCompat.getDrawable(mContext,iconResourceId);
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTintList(drawable.mutate(),mContext.gerResouces.getColorStateList());
mItemIcon.setImageDrawable(drawable);
Run Code Online (Sandbox Code Playgroud)
正如你可以看到我遇到的问题是在这一行,我在getColorStateList中传递了什么?doucmentation没有帮助我.
DrawableCompat.setTintList(drawable.mutate(),mContext.gerResouces.getColorStateList());
Run Code Online (Sandbox Code Playgroud) 我正在使用android.support.v7.widget.SwitchCompat,我遇到了以下问题
我的代码
Styles.xml
注意我试过没有父和Theme.AppCompat.Light.NoActionBar
<style name="ToggleSwitchStyle" parent="Theme.AppCompat">
<item name="colorControlActivated">@color/emerald</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我的SwitchCompat在XML布局中定义
<android.support.v7.widget.SwitchCompat
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:padding="5dp"
android:textOff="@string/no"
android:textOn="@string/yes"
app:showText="true"
android:switchPadding="5dp"
app:switchPadding="10dp"
app:theme="@style/ToggleSwitchStyle"
android:theme="@style/ToggleSwitchStyle"
android:textAllCaps="true"
app:thumbTextPadding="5dp"
>
Run Code Online (Sandbox Code Playgroud)
所以在上面的文字中,AllCaps不会使拇指上的文字全部大写.
切换填充无效
使用Res-Auto或Android命名空间的主题对活动颜色没有影响.
但是,我可以通过更改材质主题的颜色重音来更改活动颜色
<!-- Application theme. -->
<style name="MaterialDesign" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/yellow</item>
</style>
Run Code Online (Sandbox Code Playgroud) 用这个
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
Run Code Online (Sandbox Code Playgroud)
仅检测单击事件,即快速点击和释放.如果我按住然后释放,onSingleTapUp
则不会被呼叫.
我正在寻找一个ACTION_UP
持续下去的动作事件.
我看了看onShowPress
,当用户执行关闭操作的调用,但那时我不知道如何检测ACTION_UP
的同时onShowPress
.
请注意,这是为了recycler view
单击项目.目前,我可以单击一个有效的项目,但如果我按住它然后释放,则不会调用它.
嗨,所以我很困惑,想知道是否有人能指出我正确的方向.
在Lollipop和pre-lollipop上使用Google Play商店
您将在棒棒糖上看到可选择的视图具有涟漪效应.
在pre-lollipo上,你会获得这种高光效果.
这是怎么做到的?
在我的应用程序中,我有一个包含此选择器的drawable-v21目录
它基本上是在我的背景上产生涟漪
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:colorControlHighlight">
<item android:id="@android:id/mask" android:drawable="@android:color/white"/>
<item android:drawable="@color/colorAccentWith92PercentOpacity"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
但是,其他答案说要使用
机器人: "ATTR/selectableItemBackground" 背景=
要获得前棒棒糖的高光效果,但这会覆盖我的背景.我怎么能在我目前的背景之上设置它?
我还需要为我的应用程序中的每种按钮创建一个波纹drawable(在drawble-v21中)吗?我如何为回收商查看项目执行此操作?
是什么让这个问题与众不同
我不想要预先棒棒糖的涟漪我问的是开发者如何有效地使他们的按钮在棒棒糖上产生波纹并且对前的高光效果
背景:有什么问题
我的应用程序有这个词的首字母缩写词让我们假设它是
美国广播公司
当我使用 Google 的语音服务时,它会读出很棒的字母
但是,当我使用三星语音(S 语音)时,它会读出 1 个单词,这不是很好!
那么为什么不设置内容描述呢?
ABC出现在很多地方,设置替代内容描述是不可行的。它也可能会破坏其他语音服务的内容描述,这些服务可以像谷歌一样正确读出
我的计划
所以,我有一个问题了一段时间回来,我发现对于扩展类这个伟大的方法,ViewGroup
这是onRequestSendAccessibilityEvent
。综上所述,这个方法可以让你AccessibilityEvent
在处理之前捕获一个以某种方式修改它。除其他外,您还可以获取要读取的内容描述并对其进行修改。
我的想法是获取当前正在使用的 TTS 或 TalkBack 服务引擎,并使用正则表达式编辑字母 ABC 的内容描述,如果是三星语音(S 语音),则将其设为 ABC。希望!
我的问题
任何人都知道AccessibilityEvent
在全局或通用情况下处理的侦听器或回调函数吗?
onRequestSendAccessibilityEvent
仅用于ViewGroup
. 我找不到Activity
.
任何人都知道如何捕获所有传入AccessibilityEvent
或可能是我问题的替代解决方案
谢谢阅读!
我有一个编辑文本类的自定义实现.
基于这些XML属性.....
android:inputType="textPersonName"
android:inputType="textPersonName"
android:inputType="textEmailAddress"
android:inputType="textPassword"
Run Code Online (Sandbox Code Playgroud)
我希望能够在运行时知道这一点(在Java代码中)
我找到了这个方法,它给了我输入类型
getInputType()
Run Code Online (Sandbox Code Playgroud)
这些是基于我上面发布的XML返回的值.
97,97,33,129
但是,这些与此处列出的常量值不对应
http://developer.android.com/reference/android/text/InputType.html
如何在运行时知道编辑文本的输入类型?
我有这个被认为是错误的值数组
public static final String[] WRONG_VALUES = {"1000","4000","2000"};
Run Code Online (Sandbox Code Playgroud)
在我的测试中,我点击编辑文本,插入文本,然后按回来关闭键盘.
onView(withId(R.id.inputField)).perform(click(), replaceText(text), pressBack());
Run Code Online (Sandbox Code Playgroud)
然后检查错误视图是否显示
onView(withId(R.id.error)).matches(not(isCompletelyDisplayed()));
Run Code Online (Sandbox Code Playgroud)
这是有效的,但我想在测试日志中的某处输出它失败的值,因为当测试失败时我不知道正在测试哪个值这可能吗?
谢谢
我正在尝试绘制由渐变填充的圆弧
下图是我想要的
下图是我现在所拥有的
如您在图片中所见,我的渐变开始得太早了
我知道为什么会这样
如果我完成圆弧形成一个圆,我会得到这个
如我们所见,渐变从90度开始。但是我的弧线是从135度绘制的,并延伸到270度
我的问题是如何使渐变从135度开始并扫至270度?可能吗
到目前为止,这是我执行扫描渐变的方法
public void setProgressColourAsGradient(boolean invalidateNow) {
SweepGradient sweepGradient = new SweepGradient(baseArcRect.centerX(), baseArcRect.centerY(),progressGradientColourStart,progressGradientColourEnd);
//Make the gradient start from 90 degrees
Matrix matrix = new Matrix();
matrix.setRotate(90,baseArcRect.centerX(), baseArcRect.centerY());
sweepGradient.setLocalMatrix(matrix);
progressFillPaint.setShader(sweepGradient);
if (invalidateNow) {
invalidate();
}
}
Run Code Online (Sandbox Code Playgroud)
我找不到任何API来告诉SweepGradient实际从哪里开始。
我已将所有代码添加到附录部分
谢谢阅读!
评论1
我尝试将旋转设置为135度
附录A ArcWithGradient视图
public class ArcWithGradient extends View {
private Paint progressFillPaint;
private RectF baseArcRect;
private int progressGradientColourStart;
private int progressGradientColourEnd;
/**
* Thickness of the arc
*/
private int thickness;
public ArcWithGradient(Context context) …
Run Code Online (Sandbox Code Playgroud) 我从后端获得了一些用于解密一些数据的 Python 代码。在我这边,Android 应用程序,我也需要解密它。
以下是我认为最相关的一些 Python 代码片段。
cipher = PKCS1_OAEP.new(privkey)
Run Code Online (Sandbox Code Playgroud)
这是它来自的模块
from Crypto.Cipher import PKCS1_v1_5
from Crypto.Cipher import PKCS1_OAEP
Run Code Online (Sandbox Code Playgroud)
查看https://www.dlitz.net/software/pycrypto/api/2.6/Crypto.Cipher.PKCS1_OAEP-module.html的文档PKCS1_OAEP.new
然后与 Cipher 的 JavaDoc 进行比较 https://docs.oracle.com/javase/6/docs/technotes/guides/security/StandardNames.html#Cipher
我推断出这个 Python 算法可以使用 Java Cipher 类表达如下(注意代码是用 Kotlin 编写的)
val cipher = Cipher.getInstance("RSA/NONE/OAEPWithSHA1AndMGF1Padding", "BC")
Run Code Online (Sandbox Code Playgroud)
请注意,BC 是提供者。我发现BouncyCastle很受欢迎并且包含在Android框架中
那么错误是什么?
当挑战的答案错误时,后端会返回 404。当我执行 Python 代码(到达相同的端点)时,它起作用了。就POST请求而言,我比较了两者,并且我以正确的方式发送它。
我想知道什么
我使用了正确的算法吗?我正在尝试系统地排除潜在问题,然后再转向另一个问题
请注意,我也尝试过
val cipher = Cipher.getInstance("RSA/NONE/OAEPPadding", "BC")
Run Code Online (Sandbox Code Playgroud) 我试图在我的应用程序中支持RTL语言环境,但是遇到了以下问题。现在我说问题,但是由于我对RTL语言环境不熟悉,这甚至可能不是问题,所以这里就解决了。
以下是3个文本视图。注意,以下输出是通过dev选项强制启用RTL的。
英文测试LTR
强制使用英语进行RTL测试
我感到奇怪的是,即使我说它android:gravity="start"
如何与padding和margin等一起工作,它也没有正确地对齐,所以我查看了其他答案并发现了它android:textDirection="locale"
。
使用文本方向区域设置强制进行英语RTL测试
现在,这在LTR和RTL上均正确镜像,但是随后我注意到标点符号具有以下行为。不管这是否正确,这都引起了人们的关注,因为我正在与强制使用RTL的Google Play商店,Facebook和Whats App进行比较,并且在查看标点符号的段落时没有看到这一点,这使我相信自己做错了什么。
完整版式代码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="start"
android:text="@string/test_one"
android:textColor="@android:color/black"
android:textDirection="locale"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="start"
android:text="@string/test_two"
android:textColor="@android:color/black"
android:textDirection="locale"
android:textSize="24sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="start"
android:text="@string/test_three"
android:textColor="@android:color/black"
android:textDirection="locale"
android:textSize="24sp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
其他代码
我的清单文件中设置了以下内容
android:supportsRtl="true"
Run Code Online (Sandbox Code Playgroud)
这是我的琴弦
<string name="test_one">Good Job. You did well!</string>
<string name="test_two">3 hours ago</string>
<string name="test_three">Select Option:</string>
Run Code Online (Sandbox Code Playgroud)
请原谅这听起来多么幼稚,并启发我!我希望提供舒适的RTL支持!