我正在使用Parse SDK构建我的应用程序.
我可以使用Intents轻松地从库中获取Bitmap.我想将它们用作我的用户的个人资料图片.
但是,为了上传它,我必须将其转换为字节数组.此外,当我下载它时,它以字节数组的形式出现,我必须将其转换回Drawable.
为了将其转换为字节数组,我这样做:
public static byte[] bitmapToByteArray(Bitmap bmp)
{
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
return byteArray;
}
Run Code Online (Sandbox Code Playgroud)
我找不到如何将此byte []转换回Bitmap而不必先保存它.如何实现这一过程?
我正在尝试以编程方式将a设置StateListDrawable为库项目的自定义视图的背景.这是我正在做的事情:
final TypedArray a = getContext().obtainStyledAttributes(attrs,
R.styleable.ActionBar);
int firstColor = a.getColor(
R.styleable.ActionBar_backgroundGradientFirstColor, 0xff000000);
int secondColor = a
.getColor(R.styleable.ActionBar_backgroundGradientSecondColor,
0xff000000);
int textViewColor = a.getColor(R.styleable.ActionBar_titleColor,
0xffffffff);
int onClickColor = a.getColor(
R.styleable.ActionBar_backgroundClickedColor, 0xff999999);
a.recycle();
StateListDrawable sld = new StateListDrawable();
GradientDrawable drawable = new GradientDrawable(
Orientation.TOP_BOTTOM, new int[] { firstColor, secondColor });
sld.addState(new int[] { android.R.attr.state_enabled },
new ColorDrawable(onClickColor));
sld.addState(new int[] { android.R.attr.state_pressed }, drawable);
action2.setBackgroundDrawable(sld);
action3.setBackgroundDrawable(sld);
actionBack.setBackgroundDrawable(sld);
pb.setBackgroundDrawable(drawable);
tv.setBackgroundDrawable(drawable);
tv.setTextColor(textViewColor);
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用:它总是绘制启用状态.我希望它来绘制按下时,我的状态按下按钮.我究竟做错了什么?
我有一个经过验证的代码来从Excel文件中获取信息.它在java中创造奇迹.但是,当我尝试在Android中使用它时,我得到了这个:
11-30 13:26:24.339: I/dalvikvm(9762): Could not find method org.apache.commons.codec.digest.DigestUtils.md5, referenced from method org.apache.poi.hssf.usermodel.HSSFWorkbook.addPicture
Run Code Online (Sandbox Code Playgroud)
所以,当我尝试读取一行时,它总是返回null.
我该如何解决这个问题?
我在地图中添加了地理定位事件,我正在添加标记,当我点击它们时,我只是希望它们在不居中的情况下进行更改.
当我点击标记时,有没有办法覆盖居中的标记(以及被调用的onCameraChanged)?
android google-maps google-maps-markers centering android-maps-v2
我在Tumblr和Telegram应用程序上都看到了这种模式.
当您处于详细视图(在Tumblr上搜索标签或在Telegram上的对话中)并从左向右滑动时(就像您要拉动一样Navigation Drawer),您可以看到之前的活动从那里出现.如果您将其释放,则活动结束.
这个行为是如何实现的?
在我设置选择时,会在此处调用监听器.这里的问题是,我在监听器之前设置选择.
我该如何避免这种行为?
Spinner spCategories = (Spinner) findViewById(R.id.spinnerCategories);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, R.layout.spinner_item, this.categoryList);
spCategories.setAdapter(aa);
spCategories.setSelection(selectedA);
spCategories.setOnItemSelectedListener(oiclSpCategories);
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,它使用虚拟货币来执行某些操作。每次点击广告时,您都会获得“硬币”。
这是否违反 AdMob TOS?
我有一个布尔的简单活动.我希望它从纵向更改为横向,当且仅当该布尔值为假时(当然,仅当屏幕改变方向时).
我试过这个:
@Override
public void onConfigurationChanged(final Configuration newConfig) {
super.onConfigurationChanged((listening) ? getListeningConfiguration(newConfig)
: newConfig);
setContentView(R.layout.medidor);
preconfigureLayout();
}
public Configuration getListeningConfiguration(final Configuration c) {
c.orientation = Configuration.ORIENTATION_PORTRAIT;
return c;
}
Run Code Online (Sandbox Code Playgroud)
但它根本行不通.
除非我告诉它可以改变,否则如何强制活动保持纵向状态?
在一个自定义事件中,我需要我Marker更新它的drawable 6次(基本上,我希望Marker在每次增长和每次收缩之间延迟0.5秒增长和缩小3次),因此它会通知用户所述事件.
有没有办法实现这一点,而不必实际删除Marker并再次添加不同的Drawable?
我试图通过anko在FloatingActionButton中建立一个BOTTOM | END引力
floatingActionButton {
id = FAB_ID?
}.lparams {
margin = dip(16)
gravity = Gravity.BOTTOM | Gravity.END
}
Run Code Online (Sandbox Code Playgroud)
然而,似乎Kotlin不承认|运营商.我应该做些什么?