我试图将Drawable中的图像附加到电子邮件中(从我的应用程序到Gmail应用程序)
我试过下一个代码:
Intent emailintent2 = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailintent2.setType("image/*");
emailintent2.putExtra(Intent.EXTRA_EMAIL, emailaddress2);
emailintent2.putExtra(Intent.EXTRA_SUBJECT, CorAsunto);
emailintent2.putExtra(Intent.EXTRA_TEXT, message2);
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.image1));
uris.add(Uri.parse("android.resource://" + getPackageName() + "/" + R.drawable.image2));
emailintent2.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
startActivity(emailintent2);
Run Code Online (Sandbox Code Playgroud)
但是当我将图像附加到电子邮件时,我得到的附件没有扩展名".png",这就是一个大问题.
所以我想在尝试将这个Drawable图像转换为Bitmap时,我认为ArrayList必须是Bitmap.我想我会得到图像在附件中定义的图像.
如果有可能,有人可以告诉我该怎么做吗?转换为位图,添加到Arraylist并附加图像.
如果我说的都错了,有人可以给我一个解决方案吗?我需要将Drawable中的图像附加到带有扩展名(.png)的电子邮件中.
我有一个表单,我从我从Web服务收到的数据动态生成.此Web服务提供了在创建输入元素时需要使用的图像.我很难设定progressDrawable
一个RatingBar
.虽然XML我能够使用以下内容应用自定义图像progressDrawable
:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+android:id/background" android:drawable="@drawable/custom_star" />
<item android:id="@+android:id/secondaryProgress" android:drawable="@drawable/custom_star" />
<item android:id="@+android:id/progress" android:drawable="@drawable/custom_star" />
</layer-list>
Run Code Online (Sandbox Code Playgroud)
其中custom_star
是一个简单的.png图像,并且具有@android:style/Widget.RatingBar
RatingBar样式.这很好用:
但我想custom_star
动态改变.
在代码中,我尝试直接使用位图设置进度drawable:
Drawable d = new BitmapDrawable(getResources(), downloadedImage);
ratingBar.setProgressDrawable(d);
Run Code Online (Sandbox Code Playgroud)
并通过构建layer-list
:
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[] {
getResources().getDrawable(R.drawable.custom_star),
getResources().getDrawable(R.drawable.custom_star),
getResources().getDrawable(R.drawable.custom_star)
});
layerDrawable.setId(0, android.R.id.background);
layerDrawable.setId(1, android.R.id.secondaryProgress);
layerDrawable.setId(2, android.R.id.progress);
ratingBar.setProgressDrawable(layerDrawable);
Run Code Online (Sandbox Code Playgroud)
对我来说都不适用; 两者都会导致custom_star
出现一次拉伸,拉伸的尺寸为RatingBar
:
有任何想法吗?
更新:
Luksprog在下面的回答有所改进,但我仍有一些问题.现在,星形drawable没有被拉伸,并且可以通过触摸设置值,但是如果选择3/5则显示为:
和5/5选择:
我相信图像的缩放可以通过一些调整来修复,但令人讨厌的是,secondaryProgress
可绘制的东西似乎没有设置 - 用于灰色未选择的星星的可绘制.没有它,它不是很有用.
我收到这个错误.我怎么能在我的情况下解决这个问题?
"Bitmap cannot be resolved to a type"
Run Code Online (Sandbox Code Playgroud)
发生错误的行
public void onPageStarted(WebView view, String url, Bitmap favicon) {
Run Code Online (Sandbox Code Playgroud)
我的代码
public class MainActivity extends Activity {
private Activity activity = this;
private String title = "";
private ActionBar mActionBar;
private SimpleSideDrawer mNav;
WebView myWebView;
int width, height;
float flick_width;
float flick_height;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
title = activity.getTitle().toString(); // (1)
requestWindowFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.activity_main);
getSize();
mActionBar = getActionBar();
mActionBar.hide();
mNav = new SimpleSideDrawer(this);
mNav.setLeftBehindContentView(R.layout.activity_behind_left_simple, this);
mNav.setRightBehindContentView(R.layout.activity_behind_right_simple, this);
myWebView = (WebView)findViewById(R.id.webView1); …
Run Code Online (Sandbox Code Playgroud)