标签: android

更改textview时的动画

我目前使用一个主要的解决方法,并在每次更改TextView上的文本时切换两个活动.我正在使用此代码:

Weeklytext.this.overridePendingTransition( 
                    R.anim.slide_in_left, 
                    R.anim.slide_out_right
            );
Run Code Online (Sandbox Code Playgroud)

是否可以在一个活动中执行此操作?有两个活动具有完全相同的内容只是为了让我可以使用动画,这有点烦人;)

谢谢!请问你是否理解我的问题!

animation android textview

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

如何从资产加载图像?

我需要从资产加载图像,以避免在某些特定情况下调整POT图像的froyo 2.2.2错误.避免它的方法是从资源目录加载图像文件.

我正试着这样做:

        String imagePath = "radiocd5.png";
    AssetManager mngr = context.getAssets();
    // Create an input stream to read from the asset folder
    InputStream is=null;
    try {
        is = mngr.open(imagePath);
    } catch (IOException e1) {  e1.printStackTrace();}

    //Get the texture from the Android resource directory
    //InputStream is = context.getResources().openRawResource(R.drawable.radiocd5);
    Bitmap bitmap = null;
    try {
        //BitmapFactory is an Android graphics utility for images
        bitmap = BitmapFactory.decodeStream(is);

    } finally {
        //Always clear and close
        try {
            is.close();
            is = null;
        } catch (IOException …
Run Code Online (Sandbox Code Playgroud)

android assets

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

使用declare styleable设置自定义组件输入类型

我有一个CompositeComponent(EditText + ImageButton)当点击按钮时,将清除edittext内容.它工作正常.我的问题是为我的组件设置属性.我使用declare-styleable来设置我的组件的属性.

我成功设置了minLines,maxLines和textColor.

如何通过xml将inputtype设置为我的组件.

我的attributes.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <declare-styleable name="CET">
        <attr name="MaxLines" format="integer"/>
        <attr name="MinLines" format="integer"/>
        <attr name="TextColor" format="color"/>
        <attr name="InputType" format="integer" />
        <attr name="Hint" format="string" />
    </declare-styleable>
</resources>
Run Code Online (Sandbox Code Playgroud)

并在main_layout.xml中使用mycomponent:

<com.test.ui.ClearableEditText
        xmlns:cet="http://schemas.android.com/apk/res/com.test.ui"
        android:id="@+id/clearableEditText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        cet:MaxLines="2"
        cet:MinLines="1"
        cet:TextColor="#0000FF"
        cet:InputType="" <---I cant set this property--------->
        cet:Hint="Clearable EditText Hint">

    </com.test.ui.ClearableEditText>
Run Code Online (Sandbox Code Playgroud)

普通的Edittext用法:

<EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="numberSigned" <--------I want to use this property--------> >
Run Code Online (Sandbox Code Playgroud)

我不能在我的attribute.xml中使用ENUM.怎么引用android:inputType="numberSigned"我的 cet:InputType

编辑:

这就是我在ClearableEditText.java中分配属性的方法

TypedArray a = getContext().obtainStyledAttributes(attrs,R.styleable.CET,0, 0);

            int minLines = a.getInt(R.styleable.CET_MinLines, 1); …
Run Code Online (Sandbox Code Playgroud)

android custom-component attr

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

如何在没有Activity上下文的情况下在android中显示对话框?

这似乎应该很简单,但我在任何地方都找不到答案.我有一个Android应用程序,在后台执行网络任务.如果出现错误,我想显示错误对话框.当任务返回时,我不知道哪个Activity在前台.根据这篇文章,看起来我们不能使用应用程序上下文来显示一个对话框(事实上,如果我尝试的话,我确实会遇到崩溃).

那么我怎样才能获得当前活动的背景?同样,网络任务的接收器在Application上下文中运行,而不是在特定的Activity中运行.还有其他想法吗?

编辑:我应该澄清一下.如果我不是前台应用程序,我不想显示错误对话框.我只对我们的应用程序暂时处于前台的情况感兴趣.

android android-alertdialog

35
推荐指数
3
解决办法
4万
查看次数

在所有3个平台上推送通知(android,ios,windows phone)

我正在计划一个跨平台的应用程序.是否可以仅使用一个API /模块在所有3个(iphone,android,windowsphone)上实现推送通知?还有其他选择吗?服务器端需要做什么?请指出我正确的方向.(文档,示例代码,如果存在)提前感谢.

windows android java-ee ios

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

onCreateOptionsMenu()调用super

我正在使用OptionsMenu创建应用程序.我发现几个例子吧,但是大家都在用不同的地方调用super.onCreateOptionMenu()onCreateOptionsMenu()方法.

不同方式列表:

@Override // without super
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.mymenu, menu);
  return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.mymenu, menu);
  return true;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.mymenu, menu);
  return super.onCreateOptionsMenu(menu);
}
Run Code Online (Sandbox Code Playgroud)

我该怎么用?

android android-optionsmenu

35
推荐指数
1
解决办法
9018
查看次数

android,如何重命名文件?

在我的应用程序中,我需要录制视频.在开始录制之前,我正在为其分配名称和目录.录制完成后,用户可以重命名他的文件.我写了下面的代码,但似乎不起作用.

当用户输入文件名并单击按钮时,我会这样做:

private void setFileName(String text) {     
        String currentFileName = videoURI.substring(videoURI.lastIndexOf("/"), videoURI.length());
        currentFileName = currentFileName.substring(1);
        Log.i("Current file name", currentFileName);

        File directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES), MEDIA_NAME);
        File from      = new File(directory, "currentFileName");
        File to        = new File(directory, text.trim() + ".mp4");
        from.renameTo(to);
        Log.i("Directory is", directory.toString());
        Log.i("Default path is", videoURI.toString());
        Log.i("From path is", from.toString());
        Log.i("To path is", to.toString());
    }
Run Code Online (Sandbox Code Playgroud)

文本:是用户输入的名称.当前文件名:是我在记录MEDIA_NAME之前分配的名称:文件夹名称

Logcat显示了这个:

05-03 11:56:37.295: I/Current file name(12866): Mania-Karaoke_20120503_115528.mp4
05-03 11:56:37.295: I/Directory is(12866): /mnt/sdcard/Movies/Mania-Karaoke
05-03 11:56:37.295: I/Default path is(12866): /mnt/sdcard/Movies/Mania-Karaoke/Mania-Karaoke_20120503_115528.mp4
05-03 11:56:37.295: I/From path is(12866): …
Run Code Online (Sandbox Code Playgroud)

android file-rename

35
推荐指数
4
解决办法
7万
查看次数

如何在AOSP构建中添加APK?

我需要在我的AOSP版本中添加一些第三方APK.我应该保留这些APK的文件夹,以便在构建代码并创建映像时,它是否安装在模拟器中?

看起来系统应用程序保存在packages/app文件夹中,因此我需要知道第三方APK的保存位置.

android android-source

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

java比较器,如何按整数排序?

我试图在java中学习比较器,我在网上找到了这个很好的例子,我的问题是如何更改这些代码,以便按年龄和降序排列宠物名称,以便最老的是第一个,最小的是最后一个?

class Dog implements Comparator<Dog>, Comparable<Dog>{
private String name;
private int age;
Dog(){
}

Dog(String n, int a){
  name = n;
  age = a;
}

public String getDogName(){
  return name;
}

public int getDogAge(){
  return age;
}

// Overriding the compareTo method
public int compareTo(Dog d){
  return (this.name).compareTo(d.name);
}

// Overriding the compare method to sort the age 
public int compare(Dog d, Dog d1){
  return d.age - d1.age;
}
}

public class Example{
public static void main(String args[]){
  // Takes …
Run Code Online (Sandbox Code Playgroud)

java android sql-order-by comparator

35
推荐指数
4
解决办法
15万
查看次数

如何在Android中使用AES加密SD卡中的文件?

我想从SD卡加密图像并使用AES再次将其存储在SD卡中.主要思想是应用程序浏览图像,然后在按下按钮时对其进行加密,然后将其存储在SD卡中.所以我的形象是安全的.

我已经成功使用本教程http://www.androidsnippets.com/encryptdecrypt-strings中的 AES进行字符串加密,但我不知道如何使用图像而不是字符串来完成此操作.

这是我用字符串做的方式:

public static String encrypt(String seed, String cleartext) throws Exception  
{
    byte[] rawKey = getRawKey(seed.getBytes());
    byte[] result = encrypt(rawKey, cleartext.getBytes()); 
    return toHex(result);
}

private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception 
{
    SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
    Cipher cipher = Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
    byte[] encrypted = cipher.doFinal(clear);
    return encrypted;
}
Run Code Online (Sandbox Code Playgroud)

任何人都可以帮我提供示例代码如何使用AES 加密图像

也许它必须使用I/O文件流,但我不知道如何使用此代码实现.

encryption android file aes

35
推荐指数
1
解决办法
4万
查看次数