我刚刚将我的一个应用程序调整到新的v22.1.1支持和appcompat库,请参阅此处和此处了解更多详细信息.当我做一些测试时,我正在使用的ActionModes出现了问题.
当您使用调用启动ActionMode时startSupportActionMode() - 如果您使用现已弃用的ActionBarActivity基类或新的AppCompatActivity基类 - onPrepareActionMode()则不会被调用.
在onPrepareActionMode()最初使用时创建ActionMode时,会自动调用先前版本(包括v21.0.3和v22.0.0)startSupportActionMode().
我在2.2,4.4.2和5.0设备上测试了它,所以它似乎不依赖于版本.
有谁知道,如果这是预期的行为,那是在v22.1.1中引入的,还是一个bug?
我发现了这个问题,但这里没有很多反馈......
2015年5月11日编辑:
如Android问题跟踪器159527中所述,此问题不仅影响appcompat和支持库的v22.1.x,还影响5.1 Android实现.
目前有两种可能的临时解决方案,一般是:
@Override
public ActionMode startSupportActionMode(final ActionMode.Callback callback) {
// Fix for bug https://code.google.com/p/android/issues/detail?id=159527
final ActionMode mode = super.startSupportActionMode(callback);
if (mode != null) {
mode.invalidate();
}
return mode;
}
Run Code Online (Sandbox Code Playgroud)
和一个'快速和脏'的(当你实例化你的ActionMode时):
final ActionMode actionMode = startSupportActionMode(new MyActionMode());
if(actionMode != null) {
actionMode.invalidate();
}
Run Code Online (Sandbox Code Playgroud)
如果您不使用appcompat(ActionBarActivity/ AppCompatActivity),则需要替换 …
android android-appcompat android-support-library android-actionmode
我正在使用Canvas创建一个带有一些背景和一些文本的Drawable.drawable用作EditText内的复合drawable.
文本是通过画布上的drawText()绘制的,但在某些情况下,我确实遇到了绘制文本的y位置问题.在这些情况下,某些字符的部分被截断(参见图像链接).
没有定位问题的字符:
http://i50.tinypic.com/zkpu1l.jpg
有定位问题的字符,文字包含'g','j','q'等:
http://i45.tinypic.com/vrqxja.jpg
您可以找到一个代码段来重现下面的问题.
有没有专家知道如何确定y位置的正确偏移量?
public void writeTestBitmap(String text, String fileName) {
// font size
float fontSize = new EditText(this.getContext()).getTextSize();
fontSize+=fontSize*0.2f;
// paint to write text with
Paint paint = new Paint();
paint.setStyle(Style.FILL);
paint.setColor(Color.DKGRAY);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.SERIF);
paint.setTextSize((int)fontSize);
// min. rect of text
Rect textBounds = new Rect();
paint.getTextBounds(text, 0, text.length(), textBounds);
// create bitmap for text
Bitmap bm = Bitmap.createBitmap(textBounds.width(), textBounds.height(), Bitmap.Config.ARGB_8888);
// canvas
Canvas canvas = new Canvas(bm);
canvas.drawARGB(255, 0, 255, 0);// for visualization
// y …Run Code Online (Sandbox Code Playgroud) 我正在迁移我正在使用的对话框,Activity.showDialog(DIALOG_ID);以便DialogFragment在android参考中讨论使用该 系统.
在使用回调将一些事件传递回打开对话框的活动/片段时,我的开发过程中出现了一个问题:
这是一个简单对话框的示例代码:
public class DialogTest extends DialogFragment {
public interface DialogTestListener {
public void onDialogPositiveClick(DialogFragment dialog);
}
// Use this instance of the interface to deliver action events
static DialogTestListener mListener;
public static DialogTest newInstance(Activity activity, int titleId, int messageId) {
udateListener(activity);
DialogTest frag = new DialogTest();
Bundle args = new Bundle();
args.putInt("titleId", titleId);
args.putInt("messageId", messageId);
frag.setArguments(args);
return frag;
}
public static void udateListener(Activity activity) {
try {
// Instantiate the NoticeDialogListener …Run Code Online (Sandbox Code Playgroud) android dialog callback orientation-changes android-dialogfragment