我正在为应用程序创建UI,我正在尝试使用灰度图标,并允许用户将主题更改为他们选择的颜色.要做到这一点,我试图只应用某种ColorFilter来覆盖drawable顶部的颜色.我尝试过使用PorterDuff.Mode.MULTIPLY,它几乎完全按照我的需要工作,除了白色也覆盖了颜色.我理想的是像Photoshop中的"颜色"混合模式,图形保留其透明度和亮度,只修改图像的颜色.例如:
变
在做了一些研究后,看起来ColorMatrixColorFilter类可能会做我需要的,但我似乎无法找到指向矩阵如何使用的任何资源.它是一个4x5矩阵,但我需要知道的是我如何设计矩阵.有任何想法吗?
编辑:好的,到目前为止我发现的内容如下:
1 0 0 0 0 //red
0 1 0 0 0 //green
0 0 1 0 0 //blue
0 0 0 1 0 //alpha
Run Code Online (Sandbox Code Playgroud)
此矩阵是单位矩阵(应用时,不做任何更改),数字范围从0到1(浮点数).该矩阵将与每个像素相乘以转换为新颜色.所以这就是我开始变得模糊的地方.所以我认为每个像素都是1 x 4向量,其中包含0.2, 0.5, 0.8, 1
将用变换矩阵点缀的argb值(例如).因此,要使图像的红色强度加倍,您可以使用以下矩阵:
2 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
Run Code Online (Sandbox Code Playgroud)
这会给你一个矢量(颜色)0.4, 0.5, 0.8, 1
.从有限的测试,这似乎是这种情况,并且工作正常,但我实际上仍然有同样的问题(即白人获得着色).进一步阅读告诉我,这是因为它正在对RGB值进行转换,而对于色调偏移,应首先将值转换为HSL值.所以我可能会编写一个可以读取图像并转换颜色的类,并用新颜色重绘图像.这会产生StateListDrawables的另一个问题,因为我不知道如何在代码中获取每个代码并修改所有这些问题,以及它将会有多慢.:/
嗯,好吧,所以我想我的另一个问题是矩阵是否可以用于将RGB转换为具有光度信息的另一个颜色空间,例如L a b或HSL?如果是这样,我可以将该转换的矩阵相乘,然后将色调调整为THAT矩阵,然后将该矩阵应用为ColorFilter.
好吧,我一直在阅读和搜索,现在我正在撞墙,试图解决这个问题.这是我到目前为止所拥有的:
package com.pockdroid.sandbox;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.widget.ImageView;
public class ShadowImageView extends ImageView {
private Rect mRect;
private Paint mPaint;
public ShadowImageView(Context context)
{
super(context);
mRect = new Rect();
mPaint = new Paint();
mPaint.setAntiAlias(true);
mPaint.setShadowLayer(2f, 1f, 1f, Color.BLACK);
}
@Override
protected void onDraw(Canvas canvas)
{
Rect r = mRect;
Paint paint = mPaint;
canvas.drawRect(r, paint);
super.onDraw(canvas);
}
@Override
protected void onMeasure(int w, int h)
{
super.onMeasure(w,h);
int mH, mW;
mW = getSuggestedMinimumWidth() < …
Run Code Online (Sandbox Code Playgroud) 我试图让自定义对话框显示为从文本视图向下滑动.这可能吗?我似乎无法将任何动画应用于对话框类.我在构造函数中尝试过这一行,但它没有效果:
.this.getWindow()setWindowAnimations(R.anim.paranimation);
我甚至不确定动画是否正确,但是一旦我看到它正在做什么,我就能调整它.为了完整起见,我会在下面列出它.我不是在寻找实际动画的帮助,只是寻找对话框的应用程序.
paranimation.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-200%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="3000"
android:zAdjustment="top">
</translate>
Run Code Online (Sandbox Code Playgroud) 所以我在尝试设置视图的背景可绘制时有点混乱.该代码依赖于知道视线的高度,所以我不能把它onCreate()
或onResume()
,因为getHeight()
返回0 onResume()
似乎是最接近我可以得到虽然.我应该在哪里放置如下所示的代码,以便在显示给用户时背景发生变化?
TextView tv = (TextView)findViewById(R.id.image_test);
LayerDrawable ld = (LayerDrawable)tv.getBackground();
int height = tv.getHeight(); //when to call this so as not to get 0?
int topInset = height / 2;
ld.setLayerInset(1, 0, topInset, 0, 0);
tv.setBackgroundDrawable(ld);
Run Code Online (Sandbox Code Playgroud) 是否可以基于正则表达式字符串在Outlook 2007中创建规则?
我想添加过滤器包含一个字符串,如消息:4000-10
,四位数字后加破折号后两位数,这可以从任何东西0000-00
到9999-99
.
我正在使用它作为正则表达式:\b[0-9]{4}\-[0-9]{2}\b
但过滤器不起作用.我也尝试过其他一些修改但没有运气.我无法在网上找到关于Outlook是否支持将正则表达式纳入规则的具体内容,所以我想我会问这里以防万一我浪费时间.
编辑:感谢Chris在下面的评论,我能够通过宏实现这个过滤器.我想我会在下面分享我的代码,以防它能够帮助其他人:
Sub JobNumberFilter(Message As Outlook.MailItem)
Dim MatchesSubject, MatchesBody
Dim RegEx As New RegExp
'e.g. 1000-10'
RegEx.Pattern = "([0-9]{4}-[0-9]{2})"
'Check for pattern in subject and body'
If (RegEx.Test(Message.Subject) Or RegEx.Test(Message.Body)) Then
Set MatchesSubject = RegEx.Execute(Message.Subject)
Set MatchesBody = RegEx.Execute(Message.Body)
If Not (MatchesSubject Is Nothing And MatchesBody Is Nothing) Then
'Assign "Job Number" category'
Message.Categories = "Job Number"
Message.Save
End If
End If
End Sub
Run Code Online (Sandbox Code Playgroud) 我想将Twitter集成到我的Android应用程序中,以便我可以将消息发布到Twitter.
我什么时候应该使用unregisterReceiver?在onPause()
,onDestroy()
或onStop()
?
注意:我需要该服务在后台运行.
更新:
我发布接收器的异常null
.
活动已泄露意图接收器是你错过了呼叫 unregisterReceiver();
请告诉我是否有什么问题,这是我的代码:
private boolean processedObstacleReceiverStarted;
private boolean mainNotificationReceiverStarted;
protected void onResume() {
super.onResume();
try {
registerReceivers();
} catch (Exception e) {
Log.e(MatabbatManager.TAG,
"MAINActivity: could not register receiver for Matanbbat Action "
+ e.getMessage());
}
}
private void registerReceivers() {
if (!mainNotificationReceiverStarted) {
mainNotificationReceiver = new MainNotificationReceiver();
IntentFilter notificationIntent = new IntentFilter();
notificationIntent
.addAction(MatabbatManager.MATABAT_LOCATION_ACTION);
notificationIntent
.addAction(MatabbatManager.MATABAT_New_DATA_RECEIVED);
notificationIntent
.addAction(MatabbatManager.STATUS_NOTIFCATION_ACTION);
registerReceiver(mainNotificationReceiver, notificationIntent);
mainNotificationReceiverStarted = true;
}
if (!processedObstacleReceiverStarted) {
processedObstacleReceiver …
Run Code Online (Sandbox Code Playgroud) 好吧,所以我正在尝试将数据备份实施到我的应用程序中,并且一直在遵循本指南.我已经实现了我的BackupAgentHelper
使用SharedPreferencesBackupHelper
.我没有得到任何错误,并且我确定dataChanged()
在所有首选项更改后调用,但是当我测试备份(`adb shell bmgr run)时,我在LogCat中获取此信息:
07-07 12:29:00.258: V/BackupManagerService(291): Scheduling immediate backup pass
07-07 12:29:00.258: V/BackupManagerService(291): Running a backup pass
07-07 12:29:00.258: V/BackupManagerService(291): clearing pending backups
07-07 12:29:00.258: V/PerformBackupTask(291): Beginning backup of 1 targets
07-07 12:29:00.289: V/BackupServiceBinder(291): doBackup() invoked
07-07 12:29:00.289: D/PerformBackupTask(291): invokeAgentForBackup on @pm@
07-07 12:29:00.297: I/PerformBackupTask(291): no backup data written; not calling transport
Run Code Online (Sandbox Code Playgroud)
所以为了参考,在我的清单中我添加了:
<application
android:allowBackup="true"
android:backupAgent="com.kcoppock.sudoku.SudokuBackupAgent"
Run Code Online (Sandbox Code Playgroud)
以及
<meta-data
android:name="com.google.android.backup.api_key"
android:value="my_key_goes_here" />
Run Code Online (Sandbox Code Playgroud)
我的BackupAgentHelper实现如下:
public class SudokuBackupAgent extends BackupAgentHelper {
static final String …
Run Code Online (Sandbox Code Playgroud) 我正在尝试将画布绘制操作剪切成弧形楔形.但是,在将剪切路径设置为画布后,我没有得到预期的结果.
为了说明,这是我正在做的事情:
path.reset();
//Move to point #1
path.moveTo(rect.centerX(), rect.centerY());
//Per the documentation, this will draw a connecting line from the current
//position to the starting position of the arc (at 0 degrees), add the arc
//and my current position now lies at #2.
path.arcTo(rect, 0, -30);
//This should then close the path, finishing back at the center point (#3)
path.close();
Run Code Online (Sandbox Code Playgroud)
这是有效的,当我简单地绘制这个路径(canvas.drawPath(path, paint)
)时,它会绘制如上所示的楔形.但是,当我将此路径设置为画布的剪切路径并将其绘制到其中时:
//I've tried it with and without the Region.Op parameter
canvas.clipPath(path, Region.Op.REPLACE);
canvas.drawColor(Color.BLUE);
Run Code Online (Sandbox Code Playgroud)
我得到以下结果(仅留下楔形以显示参考):
所以它似乎剪切到了它的边界矩形Path
,而不是它 …
android ×9
alert ×1
animation ×1
backup ×1
colorfilter ×1
colormatrix ×1
dialog ×1
drawable ×1
drawing ×1
dropshadow ×1
height ×1
imageview ×1
layout ×1
outlook-2007 ×1
outlook-vba ×1
overriding ×1
regex ×1
textview ×1
twitter ×1
vba ×1
vbscript ×1