小编Cha*_*dru的帖子

在Android studio中更新buildToolsVersion '23 .0.1'后出现内存问题

我更新后经常出现内存问题buildToolsVersion '22.0.1',buildToolsVersion '23.0.1'我真的很困惑,不知道如何解决这个问题,因为这个错误仅显示buildTools版本23.0.1.而当我改变它时它工作正常22.0.1.请帮我.我发布的错误如下,

Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: GC overhead limit exceeded
Uncaught translation error: java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Java heap space
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.transform.api.TransformException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_25\bin\java.exe'' finished with non-zero exit …
Run Code Online (Sandbox Code Playgroud)

android build-tools android-build android-studio build.gradle

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

如何在工具栏Android中的SearchView小部件中删除白色下划线

我在我的项目中使用工具栏搜索小部件.一切正常,但期待我完全坚持删除工具栏中搜索字段下方的下划线.我尝试过很多解决方案但没有任何效果.以下是我尝试过的一些解决方案.

要求是删除图像中的白色下划线

在此输入图像描述

Ist解决方案:

//Removing underline

    int searchPlateId = searchView.getContext().getResources().getIdentifier("android:id/search_plate", null, null);
    View searchPlate = searchView.findViewById(searchPlateId);
    if (searchPlate!=null) {
        searchPlate.setBackgroundColor (Color.TRANSPARENT);
        int searchTextId = searchPlate.getContext ().getResources ().getIdentifier ("android:id/search_src_text", null, null);

    }
Run Code Online (Sandbox Code Playgroud)

第二解决方案:

 EditText searchEdit = ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text));
 searchEdit.setBackgroundColor(Color.TRANSPARENT);
Run Code Online (Sandbox Code Playgroud)

上面的代码用于更改EditText的背景,但仍然下划线显示在SearchBar中的关闭图标下方.

我用于SearchBar小部件的完整代码如下:

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater infl) {
        super.onCreateOptionsMenu(menu, infl);
        MenuInflater inflater = getActivity().getMenuInflater();
        inflater.inflate(R.menu.action_search, menu);
        final SearchView searchView = (SearchView) MenuItemCompat
                .getActionView(menu.findItem(R.id.search));

        SearchManager searchManager = (SearchManager) getActivity ().getSystemService (getActivity ().SEARCH_SERVICE);
        searchView.setSearchableInfo (searchManager.getSearchableInfo (getActivity ().getComponentName ()));

        //changing edittext color
        EditText searchEdit = …
Run Code Online (Sandbox Code Playgroud)

android searchview android-search android-toolbar

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

浮动操作按钮未完全显示在片段内

我在片段中使用FAB按钮和RecyclerView.此Fragment是TabViewPager的一个实例.我遇到了FAB按钮的问题.我已将RecyclerView和fab按钮放在FrameLayout内,其中FAB按钮位于右下方.现在我遇到的问题是FAB按钮不完全可见.它的一半部分是隐藏的,如下面的屏幕截图所示.任何人都可以帮我解决这个问题.提前致谢.

在FrameLayout中使用RecyclerView的FAB

注意: FAB滚动后正确对齐.只有在理想的情况下(滚动完成之前)才会出现问题.

fragment.xml之

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
             android:layout_width="match_parent"
             android:layout_height="match_parent">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="end|bottom"
        android:layout_margin="10dp"
        app:backgroundTint="@color/red"
        android:src="@drawable/ic_done"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

tabviewpagerlayout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout        xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">


        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_scrollFlags="scroll|enterAlways" />


        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-fragments floating-action-button androiddesignsupport android-coordinatorlayout

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

背景的FAB颜色在Gingerbread版设备中没有变化

我在改变FAB的xml中的backgroundTint颜色时面临一个问题,即没有为具有Gingerbread版本的设备分配颜色.我真的很困惑,不知道为什么它表现得很奇怪.我完全坚持这个问题几个小时触发解决方案,但我不能.请帮助我提出解决问题的建议和建议.我发布了我的代码和问题的屏幕截图供您参考.提前致谢.

include_fab.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="20dp"
    android:layout_marginRight="20dp"
    app:backgroundTint="#FF0000"
    app:borderWidth="0dp"
    app:elevation="5dp"
    app:fabSize="normal"/>
Run Code Online (Sandbox Code Playgroud)

我的gradle中的设计支持库

compile 'com.android.support:design:23.0.0'
Run Code Online (Sandbox Code Playgroud)

GingerBreadKitKat 版本的屏幕截图

注意:我在GingerBread设备上方获得了我的要求的准确输出.单独使用GingerBread会出现问题.

在此输入图像描述

android android-2.3-gingerbread material-design floating-action-button androiddesignsupport

15
推荐指数
1
解决办法
1224
查看次数

如何在styles.xml android中使用android:Theme.Material(Material theme)?

在我的应用程序中,我试图android:Theme.Material在styles values-21文件夹中实现为父主题:

 <!-- res/values-21/styles.xml -->
 <resources>
 <!-- your theme inherits from the material theme -->
 <style name="AppTheme" parent="android:Theme.Material">
    <!-- theme customizations -->
      <item name="android:colorPrimary">@color/primary</item>
    <item name="android:textColorPrimary">@color/text_primary</item>
    <!-- darker variant for the status bar and contextual app bars -->
    <item name="android:colorPrimaryDark">@color/primary_dark</item>
    <!-- theme UI controls like checkboxes and text fields -->
    <item name="android:colorAccent">@color/accent</item>
    <item name="android:navigationBarColor">@color/primary_dark</item>
   </style>
 </resources>
Run Code Online (Sandbox Code Playgroud)

运行应用程序后,我到了下面 error

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Run Code Online (Sandbox Code Playgroud)

在values文件夹中.我有以下风格

<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize …
Run Code Online (Sandbox Code Playgroud)

android android-appcompat android-theme android-styles material-design

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

如何将评级栏设置为最小一颗星?

我要求为最少一颗星的用户评分,之后评级应该增加到0.5.但我的问题是用户不应该将星的最低评级更改为0.5或0. 1应该是默认评级.请帮助解决此问题并等待您之前的回复.我也尝试通过链接实现侦听器,但完全使用我的代码中的逻辑结构 是:

ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

    @Override public void onRatingChanged(RatingBar ratingBar, float rating, 
      boolean fromUser) {

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

android actionlistener ratingbar

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

使用Retrofit 2.0 POST方法获取请求正文内容

在执行enque操作之前,我需要获取请求主体并使用Retrofit 2.0执行一些逻辑操作.但遗憾的是,我无法通过服务电话获取帖子正文内容.目前搜索了很多之后,我发现好像只有一个办法loggingrequest,我现在用的改造2.0可以发布该方法通过使用HttpLoggingInterceptor具有OkHttpClient.我使用以下代码在Android Logcat中记录请求正文:

HttpLoggingInterceptor logging = new HttpLoggingInterceptor();  
       logging.setLevel(Level.BODY);
    OkHttpClient httpClient = new OkHttpClient();
    httpClient.interceptors().add(logging);

    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(baseURL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    return retrofit.create(apiClass);
Run Code Online (Sandbox Code Playgroud)

问题我面对上述方法:

  1. 请求正文仅在默认的Android Logcat上看到

02-04 01:35:59.235 5007-5035/com.example.retrofitdemo D/OkHttp:{"nameValuePairs":{"id":"1","name":"chandru","type":"user"}}

但是上面的方法只返回logcat中的响应体,我无法将其作为String或者JSONObject.尽管如果我能够使用响应体HttpLoggingInterceptor,我的请求体将一直显示在Logcat中,标签为"OkHttp",即使在应用程序进入生产之后也是如此(所以主要是这样一种解除帖子的方式logcat中的数据).

我的要求:

我需要在不对Logcat中的post数据进行修改的情况下将请求体作为String或者JSONObject任何方法获取.

我尝试了什么:

我试图获取请求正文,即使onResponse从以后Response<T> response,但我无法完成它可能.请找到我为此目的使用的代码,如下所示:

 Gson gson = new Gson();
 String responseString =  gson.toJson(response.raw().request().body());
Run Code Online (Sandbox Code Playgroud)

注意:上述转换后的请求正文使用gson.toJson方法仅返回元数据而非请求发布数据.

请提供宝贵的提示和解决方案,帮助我解决这个问题.我不知道该怎么做.过去两天我完全坚持了这一点.如果我的问题太冗长,请原谅.欢迎你提出任何建议.如果我的要求不明确,请告诉我.提前致谢.

android request okhttp jsonresponse retrofit2

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

从Android Application类刷新Dagger 2实例

我在我的模块类中有一组@Singleton@Provides方法,用于在整个应用程序中创建Singleton实例.一切都很好,除了几个瓶颈情况,如下所示:

步骤1.我正在OKHttpClient使用Auth令牌创建一个Retrofit实例,以便每次都进行经过身份验证的api调用(通过处理Auth令牌检索和插入SharedPreferences).但是,在我通过清除数据库和共享首选项值注销应用程序之后重新启动活动时,问题就开始了.

步骤2.注销后,我正在另一个请求获取auth令牌并SharedPreferences再次插入以供将来使用.

第3步:现在,如果我继续进行其余的api调用,则前面的Dagger @Singleton@Provides方法实例保持相同,除非直到我通过从最近的任务中清除它来重新启动应用程序.(新的身份验证令牌未更新)

需要修复:

  1. 如何触发Dagger提供程序方法强制再次触发或撤消它?

  2. 是否有任何方法可以像应用程序重新启动时那样刷新应用程序类数据.

请找到我项目中使用的Dagger 2架构:

NetworkModule.java(Dagger Module类)

@Module
public class NetworkModule {

  private Context context;


    public NetworkModule(Application app) {
        this.context = app;
    }


    @Provides
    @Named("network.context")
    Context providesContext() {
        return context;
    }

 @Singleton
    @Provides
    OkHttpClient providesOkHttpClient(@Named("network.context")final Context context) {


        final UserProfile userProfile = GsonUtils.createPojo(SharedPrefsUtils.getString(Constants.SHARED_PREFS.USERS_PROFILE, "",context), UserProfile.class);


        Logger.i(userProfile != null && !TextUtils.isEmpty(userProfile.getAuth_token()) ? userProfile.getAuth_token() : "----OAuth token empty---");

        OkHttpClient.Builder httpClient = new OkHttpClient.Builder(); …
Run Code Online (Sandbox Code Playgroud)

java android dependency-injection dagger dagger-2

12
推荐指数
3
解决办法
6333
查看次数

如何在Android中绘制Bezier曲线

我需要在我的项目中创建贝塞尔曲线.为了这个目的,我正在用油漆绘制一个视图,但问题是我没有得到我需要的确切形状,如下图所示.所以请帮助我解决我的代码中的解决方案和更改或修改.提前致谢.

我用来创建Bezier曲线的代码:

public class DrawView extends View {

    public DrawView (Context context) {
        super (context);
    }

    protected void onDraw (Canvas canvas) {
        super.onDraw (canvas);

        Paint pLine = new Paint () {{
            setStyle (Paint.Style.STROKE);
            setAntiAlias (true);
            setStrokeWidth (1.5f);
            setColor (Color.RED); // Line color
        }};

        Paint pLineBorder = new Paint () {{
            setStyle (Paint.Style.STROKE);
            setAntiAlias (true);
            setStrokeWidth (3.0f);
            setStrokeCap (Cap.ROUND);
            setColor (Color.RED); // Darker version of the color
        }};
        Path p = new Path ();
        Point mid = new Point ();
        // …
Run Code Online (Sandbox Code Playgroud)

android bezier best-fit-curve android-canvas

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

实现谷歌播放和搜索栏android等地图

我需要在我的项目中创建一个Google Play并使用带有过滤器的搜索栏进行映射,但我不知道如何开始.我通过自己的自定义实现尝试了它,如下所示:

在ToolBar android中自动完成TextView

MainActivity.java

toolbar = (Toolbar) findViewById(R.id.tool_bar);
        setSupportActionBar (toolbar);

        ArrayList<String> searchArrayList = new ArrayList<String>();

        searchArrayList.add("United States");
        searchArrayList.add("France");
        searchArrayList.add("United Kingdom");
        searchArrayList.add("India");
        searchArrayList.add("Indonesia");
        searchArrayList.add("Germany");
        searchArrayList.add("Spain");

        AutoCompleteAdapter adapter = new AutoCompleteAdapter(this,
                R.layout.list_item, R.id.textView1, searchArrayList);

        AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.searchAutoComplete);
        autoCompleteTextView.setDropDownWidth(getResources().getDisplayMetrics().widthPixels);
        autoCompleteTextView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

使用ArrayAdapter自定义AutoCompleteAdapter类实现

AutoCompleteAdapter.java

public class AutoCompleteAdapter extends ArrayAdapter<String> implements
        Filterable {

    private ArrayList<String> fullList;
    private ArrayList<String> mOriginalValues;
    private ArrayFilter mFilter;

    public AutoCompleteAdapter(Context context, int resource,
                               int textViewResourceId, ArrayList<String> fullList) {

        super(context, resource, textViewResourceId, fullList);
        this.fullList = fullList;
        mOriginalValues = new ArrayList<String>(fullList); …
Run Code Online (Sandbox Code Playgroud)

android android-actionbar android-search material-design android-toolbar

9
推荐指数
0
解决办法
4886
查看次数