小编e-n*_*ure的帖子

用红色替换位图中的黑色

如何在Android中以编程方式用红色(或任何其他颜色)替换位图中的黑色(忽略透明度)?我可以用一种颜色替换位图中的白色,但它不知道黑色.感谢帮助.

android

20
推荐指数
2
解决办法
2万
查看次数

使用Dropbox API上传Android文件

如何使用Dropbox API将文件(图形,音频和视频文件)上传到Dropbox?我按照Dropbox SDK Android页面上的教程进行操作,可以使样本生效.但是现在我想要上传一个实际的File对象而不是String,而是在苦苦挣扎.

示例代码没有任何问题,看起来像这样:

    String fileContents = "Hello World!";
ByteArrayInputStream inputStream = new ByteArrayInputStream(fileContents.getBytes());
try {
    Entry newEntry = mDBApi.putFile("/testing_123456.txt", inputStream, fileContents.length(), null, null);
} catch (DropboxUnlinkedException e) {
    Log.e("DbExampleLog", "User has unlinked.");
} catch (DropboxException e) {
    Log.e("DbExampleLog", "Something went wrong while uploading.");
}   
Run Code Online (Sandbox Code Playgroud)

但是当我尝试更改它并使用以下代码上传实际文件时:

    File tmpFile = new File(fullPath, "IMG_2012-03-12_10-22-09_thumb.jpg");

// convert File to byte[]
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(tmpFile);
bos.close();
oos.close();
byte[] bytes = bos.toByteArray();

ByteArrayInputStream inputStream = …
Run Code Online (Sandbox Code Playgroud)

android inputstream dropbox android-file dropbox-api

19
推荐指数
2
解决办法
3万
查看次数

如何从FragmentPagerAdapter中删除片段?

我知道这里有一些关于这方面的话题,但我找不到一个可以为我的案子工作的解决方案.

我有一个使用自定义的工作滑动图库FragmentActivity,FragmentPagerAdapter其中包含碎片列表.

在内FragmentActivity是一个ImageView"删除".如果单击,deleteMedia()则调用该函数,然后应删除当前值,FragmentFragment显示以下内容.在我的例子中我该如何做到这一点?

FragmentActivity:

public class GalleryPagerActivity extends FragmentActivity implements OnClickListener {

    private Intent intent;
    private SharedPreferences settings;
    private PagerAdapter mPagerAdapter;
    private ViewPager mPager;
    private List<Fragment> fragments;
    private List<WhiteboardMedia> wiList;

    private int selectedPosition;
    private LinearLayout llTop;
    private TextView tvTop;
    private ImageView delete;
    private ImageView share;
    private TextView tvCounter;
    private TextView tvFilename;
    private TextView tvFilesize;
    private TextView tvDate;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        try { …
Run Code Online (Sandbox Code Playgroud)

android android-fragments fragmentpageradapter android-fragmentactivity

11
推荐指数
2
解决办法
3万
查看次数

如何将relativelayout.setBackgroundDrawable()与位图一起使用?

我有一个RelativeLayout对象,并希望动态更改背景图像与动态创建的Bitmap对象(它动态更改其颜色).

我看到当我想要更新RelativeLayout对象的背景图像时,我只能选择setBackgroundDrawable()需要Drawable对象作为参数的对象.

我的问题是,如何将动态创建的Bitmap对象转换为Drawable对象?

android android-layout

9
推荐指数
2
解决办法
2万
查看次数

如何使用位图绘制路径?

我有一个小绘图应用程序,并希望使用"复杂"形状作为画笔,即一个明星.使用简单的画笔绘制已经可以使用此代码:

remotePath.reset();
remotePath.moveTo(start_x, start_y);

float dx = Math.abs(end_x - start_x);
float dy = Math.abs(end_y - start_y);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
        remotePath.quadTo(start_x, start_y, (end_x + start_x) / 2, (end_y + start_y) / 2);
}

remotePath.lineTo(end_x, end_y);
// commit the path to our offscreen
mCanvas.drawPath(remotePath, remotePaint);
// kill this so we don't double draw
remotePath.reset();
invalidate();
Run Code Online (Sandbox Code Playgroud)

我基本上想要使用这个位图相同的功能:

Bitmap myBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.brush_star);
Run Code Online (Sandbox Code Playgroud)

我的解决方案目前正在使用一个点(坐标)列表来绘制位图.该解决方案的问题在于它仅在给定点处绘制位图,导致每个绘制的位图之间存在间隙.我宁愿想要画一条平滑的线,同时用简单的画笔绘制,两者之间没有任何间隙.

位图绘制的当前代码:

        protected void onDraw(Canvas canvas) {

        // Make canvas white
        canvas.drawColor(Color.WHITE);

        // Paintable area …
Run Code Online (Sandbox Code Playgroud)

android drawing2d android-canvas

7
推荐指数
1
解决办法
9641
查看次数

ViewPager使用xml文件作为视图

我想在ViewPager(使用PagerAdapter)中使用三个先前创建的活动,以便用户可以水平平滑地滚动它们.我按照了一个很有效的教程.问题出在他们使用TextViews演示的教程中.我已经完成了活动(布局在XML文件中).我想现在在滑块中使用这些活动,但看起来我只能使用Views.我无法弄清楚如何更改类的代码(从"implements Activity"到"extends View"),我可以在滑块中使用它.

我当前的代码如下所示:

public class HorizontalSliderBeispielActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.main);

       cxt = this;
       awesomeAdapter = new AwesomePagerAdapter();
       awesomePager = (ViewPager) findViewById(R.id.awesomepager);
       awesomePager.setAdapter(awesomeAdapter);
    }
...
Run Code Online (Sandbox Code Playgroud)

然后使用PageAdapter的内部类:

...
private class AwesomePagerAdapter extends PagerAdapter {

    public Object instantiateItem(View collection, int position) {
        TextView tv = new TextView(cxt);
        tv.setText("Bonjour PAUG " + position);
        tv.setTextColor(Color.WHITE);
        tv.setTextSize(30);

        view_01 = new SubmitCheatInstructions(cxt);

        ((ViewPager) collection).addView(tv, 0);
        ((ViewPager) collection).addView(view_01 , 1);

        return tv;
    }
}
Run Code Online (Sandbox Code Playgroud)

而不是TextView"tv",我想使用活动(即SubmitCheatInstructions).以前这个课看起来像:

public class SubmitCheatInstructions implements Activity { …
Run Code Online (Sandbox Code Playgroud)

xml layout android

7
推荐指数
1
解决办法
4847
查看次数

在画布中绘制多种颜色

我制作了一个简单的绘图应用程序,我可以在画布上绘制线条.现在我想添加各种颜色选择按钮.我现在遇到的问题是,如果我单击一个颜色按钮并继续绘制所有先前绘制的线条,也会将其颜色更改为新选择的颜色.

我找到了一些关于为此目的使用绘画(或路径)列表的论坛帖子.但是,我无法完全理解解决方案.任何人都可以发布一些工作示例的代码吗?

非常感谢你提前.

android

5
推荐指数
2
解决办法
4035
查看次数

单击操作栏中的"向上"时主/详细流程中的空意图(nullpointer异常)

这可能是一个冗长的帖子,所以我提前道歉.

I'm using the master/detail flow to display a list of items and when clicking on it it opens the detail view. The items are loaded from a webservice. It works great on the tablet with the fragments but on the phone it keeps crashing. It can display the item detail (CheatViewPageIndicator.java) properly but when I use the "up" button on the top left in the action bar to return to the parent activity (CheatListActivity.java) the app keeps crashing with …

android master-detail android-intent android-fragments

5
推荐指数
1
解决办法
1053
查看次数

失败[INSTALL_PARSE_FAILED_NO_CERTIFICATES]

我无法在Intermec设备(运行Android 4.2)上安装我使用SHA-256签名的APK .我可以安装相同的APK,在Nexus 5(运行Android 6.0)上没有任何问题. 我已经检查了两个设备,两个设备确实支持SHA-256.

我得到的错误是:

C:\work\n\apks>adb install marlin-app-android-01.00.TRUNK-SNAPSHOT.apk
5136 KB/s (9431036 bytes in 1.793s)
        pkg: /data/local/tmp/marlin-app-android-01.00.TRUNK-SNAPSHOT.apk
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]
Run Code Online (Sandbox Code Playgroud)

我使用此命令对APK进行签名(使用JDK6):

jarsigner -verbose -sigalg SHA256withRSA -digestalg SHA-256 -keystore nemo.keystore marlin-app-android-01.00.TRUNK-SNAPSHOT.apk NEMO
Run Code Online (Sandbox Code Playgroud)

当我尝试将APK安装到Intermec时,我得到了这个logcat输出:

10-15 11:19:50.550      416-435/? W/ActivityManager? No content provider found for permission revoke: file:///data/local/tmp/marlin-app-android-01.00.TRUNK-SNAPSHOT.apk
10-15 11:19:50.612      416-435/? W/ActivityManager? No content provider found for permission revoke: file:///data/local/tmp/marlin-app-android-01.00.TRUNK-SNAPSHOT.apk
10-15 11:19:50.784      416-435/? W/PackageParser? Exception reading AndroidManifest.xml in /data/app/vmdl381788980.tmp
    java.lang.SecurityException: META-INF/NEMO.SF has invalid digest for res/drawable-mdpi-v4/notification.png in /data/app/vmdl381788980.tmp
            at java.util.jar.JarVerifier.invalidDigest(JarVerifier.java:134)
            at …
Run Code Online (Sandbox Code Playgroud)

android code-signing sha256 intermec apk

5
推荐指数
0
解决办法
4353
查看次数

Facebook 原生广告未显示,错误“1011 - 显示格式不匹配”

我想实现 Facebook Audience Network“原生广告”并将其显示在 RecyclerView 列表中每第 N 个位置处。我已经在同一个应用程序中运行了常规横幅,并且没有任何问题。但是,原生广告无法加载,我只是得到一个没有内容的空白矩形。

当我检查日志文件时,我可以看到我一直以 nativeAd.setAdListener(new NativeAdListener()) 的“onError”结束......收到此错误消息:

广告请求中的显示格式与为此展示位置指定的显示格式不匹配。每个展示位置只能与单一显示格式一起使用。您可以创建多个展示位置以使用多种显示格式。

我的布局 XML 如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/outer_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:orientation="vertical"
android:padding="@dimen/outer_padding_listview_item">

<com.facebook.ads.NativeAdLayout
    android:id="@+id/native_ad_container"
    android:layout_width="250dp"
    android:layout_height="280dp"
    android:layout_gravity="center"
    android:background="@color/white"
    android:orientation="vertical" />
Run Code Online (Sandbox Code Playgroud)

FacebookNativeAdListViewItemHolder.java

public class FacebookNativeAdListViewItemHolder extends RecyclerView.ViewHolder {
private static final String TAG = FacebookNativeAdListViewItemHolder.class.getSimpleName();

private final NativeAd nativeAd;
public View view;
private Context context;

@BindView(R.id.outer_layout)
LinearLayout outerLayout;
@BindView(R.id.native_ad_container)
NativeAdLayout nativeAdContainer;

public FacebookNativeAdListViewItemHolder(View view, Context context) {
    super(view);
    ButterKnife.bind(this, view);

    this.view = view;
    this.context = context;

    nativeAd = new …
Run Code Online (Sandbox Code Playgroud)

facebook-android-sdk facebook-ads-api facebook-audience-network

5
推荐指数
1
解决办法
1276
查看次数