小编mad*_*mar的帖子

android标题不会显示在工具栏中

我有一个xml,我使用片段文件这么多活动,但我的问题是我无法在工具栏中显示我想要的文本,我使用那个xml,因为我有一个导航抽屉,我需要处理一些事情所以我不得不这样做.

我的xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frame_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".StatusActivity"
    android:orientation="vertical" >

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        style="@style/ToolBarStyle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:minHeight="@dimen/abc_action_bar_default_height_material" />

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

我的一项活动:

public class GroupChatActivity extends ActionBarActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base_layout);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
         setSupportActionBar(toolbar);
         getSupportActionBar().setDisplayShowHomeEnabled(true);

         ActionBar actionBar = getSupportActionBar();
         actionBar.setTitle("Groups history");

        Aniways.init(this);

        if(savedInstanceState == null)
        {
            FragmentManager manager = getSupportFragmentManager();

            Fragment fragment = GroupChatFragment.newInstance(getIntent().getIntExtra("uid", 0));
            manager.beginTransaction().add(R.id.frame_container, fragment).commit();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我尝试将标题设置为操作栏,但它不起作用.

android toolbar android-actionbar android-actionbar-compat android-toolbar

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

Android前台服务通知未显示

我正在尝试启动前台服务.我收到通知,该服务确实启动但通知始终被抑制.我仔细检查了应用是否允许在我的设备上的应用信息中显示通知.这是我的代码:

private void showNotification() {
    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Constants.ACTION.MAIN_ACTION);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
            | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
            notificationIntent, 0);

    Bitmap icon = BitmapFactory.decodeResource(getResources(),
            R.mipmap.ic_launcher);

    Notification notification = new NotificationCompat.Builder(getApplicationContext())
            .setContentTitle("Revel Is Running")
            .setTicker("Revel Is Running")
            .setContentText("Click to stop")
            .setSmallIcon(R.mipmap.ic_launcher)
            //.setLargeIcon(Bitmap.createScaledBitmap(icon, 128, 128, false))
            .setContentIntent(pendingIntent)
            .setOngoing(true).build();
    startForeground(Constants.FOREGROUND_SERVICE,
            notification);
    Log.e(TAG,"notification shown");

}
Run Code Online (Sandbox Code Playgroud)

这是我在关系中看到的唯一错误: 06-20 12:26:43.635 895-930/? E/NotificationService: Suppressing notification from the package by user request.

notifications android

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

OkHttp在android中用于发出网络请求

我想做什么 ::

我正在尝试学习使用Okhttp 在android中进行网络调用


我做了什么 ::

  • 在这里阅读了他们的文档
  • 我已经下载并在项目中添加了JAR
  • 我在这里使用他们的示例代码

MyCode ::

MainActivity.java

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.internal.http.Request;
import com.squareup.okhttp.internal.http.Response;
    public class MainActivity extends Activity {

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

             Request request = new Request.Builder()
                .url("https://raw.github.com/square/okhttp/master/README.md")
                .build();

            Response response = client.execute(request);

            Log.d("ANSWER", response.body().string());

        }

    }
Run Code Online (Sandbox Code Playgroud)

我面临的错误 ::

在这行Response response = client.execute(request); 我得到错误:

客户端无法解析为变量

怎么解决这个!


{}更新

public class MainActivity extends Activity {

    OkHttpClient client = new OkHttpClient(); …
Run Code Online (Sandbox Code Playgroud)

java android okhttp

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

将sdk更新为M时,无法解析导入org.apache.http.client错误

当我将项目导入eclipse时,我遇到了以下错误.我已将我的sdk更新为M.

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.CoreProtocolPNames;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
Run Code Online (Sandbox Code Playgroud)

android androidhttpclient

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

如何在maven项目中使用Google Play服务?

有人可以给我一步一步的教程,告诉我如何在maven项目中使用google play服务?我添加了两个依赖项

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>4</version>
    <type>apklib</type>
</dependency>

<dependency>
    <groupId>com.google.android.gms</groupId>
    <artifactId>google-play-services</artifactId>
    <version>4</version>
    <type>jar</type>
</dependency> 
Run Code Online (Sandbox Code Playgroud)

apklib和jar出现在maven存储库中,但未生成com.google.android.gms.R类.

我收到NoClassDefFoundError.如何将com.google.android.gms放入gen文件夹?

android maven google-play-services

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

在Android中使用矢量drawable和一组.png的图标有什么区别?

使用vector drawables和使用一组.pngAndroid系统图标有什么优缺点?

如果它们用于两种不同的东西,那是什么?

png android android-image android-drawable

14
推荐指数
2
解决办法
6164
查看次数

必须声明元素RelativeLayout

我收到错误" RelativeLayout必须声明元素",我不知道它发生的原因.如何摆脱此错误,请发布建议或代码片段.这是我的drawer_list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@id/drawer_list_item"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="@drawable/list_selector">

<ImageView
    android:id="@+id/icon"
    android:layout_width="25dp"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
    android:contentDescription="@string/desc_list_item_icon"
    android:src="@drawable/ic_launcher"
    android:layout_centerVertical="true" />

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_toRightOf="@id/icon"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:textColor="@color/material_blue_grey_900"
    android:gravity="center_vertical"
    android:paddingRight="40dp"/>

<TextView android:id="@+id/counter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/counter_bg"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:layout_marginRight="8dp"
    android:textColor="@color/material_blue_grey_900"/>

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

xml android

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

achartengine准备好实时绘图吗?

我试图绘制一些实时数据,"实时"这里意味着<10毫秒数据,理想情况下尽可能低.我已经能够让Android快速获取和处理数据,但ACE看起来并不是为了实时使用而设计的.最初的症状是垃圾收集器像没有明天一样开始并完全杀死应用程序.我正在以"滑动窗口"的方式可视化数据,所以我不希望ACE能够实时绘制数万分之一的点数.我已经看了一下它,onDraw for XYChart肯定会分配非常多的情况,它看起来很方便,可能使代码更具可读性,但并不是真正需要的.这甚至可能比以前更糟,所以它可能还没有被注意到.我看到问题#225的bugfix解决了并发问题的变化:

return mXY.subMap(start, stop);

对于:

return new TreeMap<Double, Double>(mXY.subMap(start, stop));

这会创建巨大的分配(仍然由原始子映射支持),当onDraw正在进行时排队更新可能会更好,并且稍后在原子更新或该行上的某些事情处理它们以避免并发问题.

实在可惜这里是ACE肯定是足够快的我需要什么.它可以完美地完成我在硬件上所需要的东西,但由于它在重绘Android上的分配如此严重,因为它对GC很疯狂.它很快开始分配,而GC正在运行,所以它必须等待,我的应用程序开始看起来像一个定格动画电影.

真正的问题是:期望能够使用ACE实时重绘(平板电脑应用程序)4或6个线性图表是否合理(或者是200毫秒的刷新率),还是没有为这种滥用做好准备?如果答案是否定的.你推荐的其他选择吗?

编辑20130109: 修订版471为小数据集改进了很多东西.2.000点/ 4个图表/ 100毫秒刷新率是可行和平滑的.日志仍然看到"GC_CONCURRENT释放"像疯了一样(大约10 /秒),但没有"WAIT_FOR_CONCURRENT_GC被阻止"这些是使你的应用程序停止运动的showstoppers.在3.000点/ 1图表/ 100毫秒,它显然顺利.我们再次在logcat和口吃应用程序上发生了"WAIT_FOR_CONCURRENT_GC阻塞"的雪崩.再次看起来我们没有速度问题,只有内存管理问题.

可能看起来我可能会要求ACE做魔法,但是在重构我的所有代码以检索和存储1KHz的遥测数据之后我碰到了这堵墙.一旦我终于看到我的应用程序检索并存储了所有这些实时而没有触发GC,我试图绘制时用ACE拉我的头发:)

android achartengine

9
推荐指数
1
解决办法
3465
查看次数

无法规范化文件'E:\ WorkSpace\mapdemo\app\build\intermediates\mockable-Google Inc.:Google API:21.jar'的路径

我正在尝试运行此应用程序,但它给了我错误,我不明白这个错误的含义?

我在build.gradle文件中也添加了google play服务库:

apply plugin: 'com.android.application'

android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "act.com.mapdemo"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Run Code Online (Sandbox Code Playgroud)

我的xml文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

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

当我运行它时给我错误:

Gradle 'mapdemo' project refresh failed

Error:Could not normalize path for file 'E:\WorkSpace\mapdemo\app\build\intermediates\mockable-Google Inc.:Google APIs:21.jar'.
The filename, …
Run Code Online (Sandbox Code Playgroud)

java android android-studio

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

在Android Studio中的远程服务器上构建本地gradle app

我当前项目的大小(包括依赖项)一直在增长,这意味着现在我的本地计算机上需要大约2分钟才能创建当前项目gradle build.

我们已经有一个基于推送的CI系统,但是还有一种方法可以使用云资源构建本地版本并将其拉回本地计算机,以便在仿真器或连接设备中进行测试和调试?

是的,解决方案是购买更快的PC,但这并不能很好地扩展,因为我们的工程团队也在不断增长.因此,租用一台cloudserver正在进行大量CPU工作的人将是一个非常经济的选择.

cloud android build android-gradle-plugin android-studio-2.0

9
推荐指数
1
解决办法
1162
查看次数