小编Dip*_*iya的帖子

Android:是否可以扩展xml drawable?

这是我想要做的:我有这个比例xml:

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:drawable="@drawable/mydrawable" 
    android:scaleGravity="bottom"
    android:scaleHeight="50%" />
Run Code Online (Sandbox Code Playgroud)

我想将它与这个可绘制的xml一起使用:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android"
            android:shape="rectangle">
            <gradient android:startColor="#FFFFFFFF"
                android:endColor="#FFFF0000"
                android:angle="90" />
        </shape>
    </item>
</layer-list>
Run Code Online (Sandbox Code Playgroud)

然后我将scale xml设置为LinearLayout的背景,但我没有看到任何内容.我错过了什么或者不可能这样做(使用XML)?

xml android shape scale

14
推荐指数
1
解决办法
7599
查看次数

如何从电子邮件中的资产附加pdf文件?

如何在我的应用程序中将资产中的pdf文件附加到电子邮件中?我使用以下代码附加图像,但我不知道如何附加PDF.

EMail.java文件

package com.drc.email;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Email extends Activity {
    Button send,attach;
    EditText userid,password,from,to,subject,body;

    private static final int SELECT_PICTURE = 1;
    private String selectedImagePath=null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        send = (Button) this.findViewById(R.id.btnsend);
        attach = (Button) this.findViewById(R.id.btnattach);
        userid = (EditText) this.findViewById(R.id.userid);
        password = (EditText) …

android android-assets

13
推荐指数
1
解决办法
4718
查看次数

onNewIntent(intent)无法正常工作

我正在构建这个Twitter应用程序,其中调用浏览器以从我的主要活动进行身份验证..在线程中运行以下代码(AsyncTask)

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)).setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_FROM_BACKGROUND);
context.startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

这里

context is the context of main activity..the uri is returned through `intent`..
Run Code Online (Sandbox Code Playgroud)

在认证之后,它要做的是回到我的主要活动,到现在的状态.现在发生的是,它创建了另一个主要活动的实例.

我在用

@Override
public void onNewIntent(Intent intent) {
    super.onNewIntent(intent); 
    SharedPreferences prefs = getSharedPreferences("twitter", 0);
    final Uri uri = intent.getData();
    if (uri != null && uri.getScheme().equals(Constants.OAUTH_CALLBACK_SCHEME)) {

        setLoggedIn(true, tlogout);
        tstatus=true;

        new RetrieveAccessTokenTask(this,consumer,provider,prefs,tstring).execute(uri);

    }
}
Run Code Online (Sandbox Code Playgroud)

但仍然,问题仍然存在..另一件事是,一切正常模拟器(2.3)..不能在我的设备工作.. Android 2.3.6

我的清单是

<activity
    android:name=".mainActivity"

    android:launchMode="singleTask"

    android:label="@string/title_activity_main" >
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="x-oauthflow-twitter" android:host="callback" …
Run Code Online (Sandbox Code Playgroud)

android oauth

13
推荐指数
1
解决办法
3708
查看次数

PhoneGap Android入门"缺少以下其中一项"

我目前正在关注开始使用PhoneGap的本教程.我已经安装了所有内容并在系统变量上设置路径.

但是当我要构建项目时,它总是会出错

缺少以下之一:JDK Android SDK Apache ant

我在命令提示符下检查了命令,java,adb,ant.java和adb似乎工作得很好,但是ant返回错误"Build.xml不存在.构建失败".

如何生成项目文件?

android cordova

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

如何在Android中设置ImageView的onClicklistener方法?

我正在添加一个ImageViews 数组并ImageView动态设置图像,我完成了它.但问题是如何设置/定义onClicklistener方法ImageView

这是我的代码:

ImageView[] mImages;
int[] images={R.drawable.sandle_icon1, R.drawable.sandle_icon2,
            R.drawable.sandle_icon3, R.drawable.sandle_icon4};

LinearLayout ll = new LinearLayout(this);
mScrollViewImage.removeAllViews();
ll.setOrientation(LinearLayout.VERTICAL);
mImages = new ImageView[images.length];
mScrollViewImage.addView(ll);
for (floop = 0; floop < sandleicon.length; floop++) {
    mImages[floop] = new ImageView(this);
    mImages[floop].setImageResource(images[floop]);
        ll.addView(mImages[floop]);
}
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激.

android android-imageview

12
推荐指数
1
解决办法
6万
查看次数

Android SDK - 来自网址的媒体播放器视频

我试图找到一个简单的教程,解释如何从URL加载到Android媒体播放器的视频,但不幸的是我找不到任何!

我尝试了几件事来尝试让它工作但仍然没有运气.

让MediaPlayerActivity从URL加载视频的最佳方法是什么?

谢谢

编辑:

我按照建议尝试了以下代码:

VideoView videoView = (VideoView) findViewById(R.id.your_video_view);
MediaController mediaController = new MediaController(this); 
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView.setVideoURI(Uri.parse("url-here"));
videoView.start();
Run Code Online (Sandbox Code Playgroud)

当我参加这项活动时,它只是崩溃了.

android android-video-player android-mediaplayer

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

如何取消选中已选中的Android复选框

我的Android应用程序中有两个单选按钮和5个复选框.还有一个保存按钮.当用户单击"保存"按钮时,我需要取消选中用户选中的复选框.我已尝试使用以下代码.但它无法正常工作.

if (chkOthers.isChecked()) 
    chkOthers.setChecked(false);
    chkOthers.setSelected(false);
}
Run Code Online (Sandbox Code Playgroud)

checkbox android

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

以编程方式设置子布局宽度在ANDROID?

在我的代码中,我有一个具有多个子布局的XML文件.我只想根据设备的屏幕宽度以编程方式设置其中一个子布局的宽度.到目前为止,我已经尝试过Layout params,setparam和其他方法,但它在获取布局ID时显示空指针异常.

我的父布局是相对布局,第一个子布局是线性布局("对于此布局我需要更改宽度")

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parentlayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout
        android:id="@+id/childlayout"
        android:layout_width="250dip"
        android:layout_height="fill_parent"
        android:orientation="vertical" 
        android:background="#153746">
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@drawable/sub_title"
            android:gravity="center_vertical" >
            <TextView
                android:id="@+id/menu_header_label"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textStyle="bold"
                android:text="asd"
                android:textColor="#ffffff"
                android:layout_marginLeft="10dip" />

            <ImageView
                android:id="@+id/menu_header"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal" />
        </LinearLayout>
        <ListView
            android:id="@+id/menu_listview"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:divider="@android:color/darker_gray"
            android:dividerHeight="1dip"
            android:scrollingCache="false" />
    </LinearLayout>

    <FrameLayout
        android:id="@+id/overlay"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >
    </FrameLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

Java代码: -

     public class SlideMenu extends LinearLayout {

    // keys for saving/restoring instance state
    public final static String KEY_MENUSHOWN = "menuWasShown";
    private final static String KEY_STATUSBARHEIGHT = …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-layout

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

活动返回图片

我想在我的活动中返回一个位图,以便其他应用程序可以使用它.

返回文本很清楚.

Intent data = new Intent();
data.putExtra("text1", "text.");
data.putExtra("text2", "longer text.");
setResult(RESULT_OK, data);
Run Code Online (Sandbox Code Playgroud)

但是如何返回位图?

更多信息:该活动有几种意图可供想要获取图像的每个人使用.

<intent-filter>
    <action android:name="android.intent.action.GET_CONTENT" />
    <category android:name="android.intent.category.OPENABLE" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
    <data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
<intent-filter>
    <action android:name="android.intent.action.PICK" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="image/*" />
    <data android:mimeType="vnd.android.cursor.dir/image" />
</intent-filter>
Run Code Online (Sandbox Code Playgroud)

编辑:这是一个功能的解决方案:

public void finish(Bitmap bitmap) {
    try {
        File folder = new File(Environment.getExternalStorageDirectory() + "/Icon Select/");
        if(!folder.exists()) {
            folder.mkdirs();
        }
        File nomediaFile = new File(folder, ".nomedia");
        if(!nomediaFile.exists()) {
            nomediaFile.createNewFile();
        }

        FileOutputStream out = …
Run Code Online (Sandbox Code Playgroud)

android image android-intent android-activity

8
推荐指数
1
解决办法
3325
查看次数

如果单击字段中的任何字母,Android将光标从一个EditText移动到另一个EditText?

我想将光标从EditText1移动到另一个EditText2.我已经专注于editText1但是如何将光标移动到editText2.

android android-edittext

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