小编Rea*_*hed的帖子

在标题之前左上角的android工具栏中显示imageview

我想在标题之前在android工具栏上显示imageview但它不起作用,它在右侧标题后给我图像,任何人都可以帮我想要图像在工具栏的开头左边 在此输入图像描述

这是我的布局:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.astro.famouspandit.Activities.Abstract.AbstractActivity">



        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="#0F6177"
            app:popupTheme="@style/AppTheme.PopupOverlay" >

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageViewplaces"
                android:src="@drawable/ic_question_mark"
                />
            </android.support.v7.widget.Toolbar>




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

这是活动

package com.astro.famouspandit.Activities.Abstract;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.astro.famouspandit.Activities.Activity.ChartStyle;
import com.astro.famouspandit.Activities.Activity.SelectLanguage;
import com.astro.famouspandit.R;

public class AbstractActivity extends AppCompatActivity {

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



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


    }


    public boolean onCreateOptionsMenu(Menu menu) …
Run Code Online (Sandbox Code Playgroud)

android

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

如何在android中的相同recyclerview中填充具有相同字段或属性的不同对象

我将开发足球应用程序,并跟随json响应.(链接)

我有两个不同的类,具有不同的名称,但具有相同的属性或字段,并希望显示一个相同的单一RecyclerView.

在这里,我有worldmatch和世界具有类似于相同的字段matchTime,startTime以及endTime.我使用jsontopojo插件创建了pojo类.

这是主要的事情,我想显示worldmatch在0位置,并根据俱乐部的其他位置世界其他地区.您可以在图片中查看更多详细信息.

在此输入图像描述

在此输入图像描述

这必须是第一个标签(世界),类似于欧洲,亚洲等具有相似模式的其他标签.

TAB1(世界)

---------------position 0 (All match)------------------
|
| 930   1100   1130  and so on ( horizontal recyclerview)
|
-------------------------------------------
---------------position 1(Barcelona)------------------
|
| 1130   1230   1330   1430  and so on (  horizontal recyclerview)
|
-------------------------------------------
---------------position 2(Chelsea)------------------
|
| 1300   1400   1500  and so on (  horizontal recyclerview)
|
-------------------------------------------
                     .
                     .
                     .
                   so on
        (vertical …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview nestedrecyclerview

10
推荐指数
1
解决办法
452
查看次数

直接onResume()调用的替代方法

我正在重写我的Android应用程序,以消除直接调用onResume().

我的应用程序目前在其中完成大部分工作onResume(),然后发布显示,这就是结束onResume().

@Override
public void onResume() {
    super.onResume();
    // get current date and time,
    //  and determine if daylight savings time is in effect.
    //...600 lines of code
    // output both the chart and report
    //
    image.setImageBitmap(heightChart);
    report.setImageBitmap(reportBitmap);
}
Run Code Online (Sandbox Code Playgroud)

下一步是收集用户输入,告诉我用户希望对报告进行哪些更改.(它可能是新位置,新日期或新显示样式等).这样做如下:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final int STATION_REQUEST = 1;
    int test = 1;
    switch (item.getItemId()) {
        case R.id.refresh: {
            userDateSet = false;
            onResume();
            return true;
        } // come to the …
Run Code Online (Sandbox Code Playgroud)

java android onresume android-lifecycle android-activity

10
推荐指数
1
解决办法
1119
查看次数

由 Android Studio 4.0.1 编译时,Android 项目将无法运行

这是一个很长的故事,我会尽量提供尽可能多的细节。

几个月来,我一直在使用 android studio 3.xx 来构建我的应用程序,直到最近它开始为我提供最新的稳定版 4.0.1 的更新。

我更新了,它应该是无忧无虑的,所有插件都更新没有错误,代码首先在新的 android studio 中编译,该项目在测试中运行良好,然后我上传到 Play 商店的内部测试轨道(这里是问题开始)。

该应用程序开始在某些设备中显示某种锁定或无限循环错误......这很奇怪,因为运行调试版本时完全相同的设备很好,此时我认为有些proguard rules是问题所在。所以我调整了build.grade文件,以使debug构建具有与构建相同的设置release(缩小和缩小 TRUE)。

编译后,应用程序在模拟器和有问题的设备中顺利运行......
我再次将其上传到谷歌播放,并从那里下载该应用程序不起作用......

我做了一个非常详尽和烦人的代码调试,以获取以某种方式被锁定的方法,我发现了这个嫌疑人:

OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
    httpClientBuilder.readTimeout(15000, TimeUnit.MILLISECONDS);
    httpClientBuilder.writeTimeout(15000, TimeUnit.MILLISECONDS);
    httpClientBuilder.connectTimeout(15000, TimeUnit.MILLISECONDS);
    httpClientBuilder.retryOnConnectionFailure(true);
    httpClientBuilder.followRedirects(true);
    httpClientBuilder.followSslRedirects(true);
    httpClientBuilder.connectionPool(DEFAULT_CONNECTION_POOL);
    Dispatcher dispatcher = new Dispatcher();
    dispatcher.setMaxRequests(10);
    dispatcher.setMaxRequestsPerHost(10);
    httpClientBuilder.dispatcher(dispatcher);
    okHttpClient = httpClientBuilder.build();

private boolean isInternetOK(){
    boolean ret = false;
    try {
        okHttpClient.newCall(new Request.Builder().get().url("https://www.google.com").build()).execute();
        ret true;
    } catch (Exception e) {                
    }
    return ret;
}
Run Code Online (Sandbox Code Playgroud)

在我的启动器活动中,在开始登录之前,我验证用户的 Internet 连接是否正常,这是一个简单的代码,并且httpclient …

android android-studio android-gradle-plugin okhttp

10
推荐指数
1
解决办法
599
查看次数

材质对话框库 - 防止在onPositive函数调用上关闭/关闭对话框

我正在使用材料对话框库,当我单击肯定按钮时,将onPositive调用该函数并关闭对话框.如何阻止对话框关闭/解除?

谢谢你的回答.

android android-dialog material-design

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

从Firebase数据库读取数据

我想从firebase数据库中读取特定数据.我目前正在做的是这里.

DatabaseReference database = FirebaseDatabase.getInstance().getReference();
DatabaseReference myRef = database.child("profiles/");

myRef.child(phoneNo).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        user = dataSnapshot.getValue(User.class);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}

});
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

写入DB的方法

public void writeToDBProfiles(Object data,String phoneNo) {
    DatabaseReference database = FirebaseDatabase.getInstance().getReference();
    DatabaseReference myRef = database.child("profiles/" + phoneNo);
    myRef.setValue(data);
}
Run Code Online (Sandbox Code Playgroud)

但它返回null ...任何帮助将不胜感激.

android firebase firebase-realtime-database

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

折叠工具栏仅适用于导航视图中的一个片段

问题

我有一个带有不同碎片的导航抽屉.每个Fragment应该使用的默认工具栏,除了Fragment需要折叠的工具栏Toolbar.

我的问题

如何在片段的工具栏之间切换?

java xml android android-layout android-fragments

9
推荐指数
3
解决办法
3138
查看次数

如何制作横向ContextMenu?

我已经打了一个Activity电话Accounts,我想添加一个横向ContextMenu.这可能看起来像剪切,复制和粘贴选项.有没有办法onLongClick在列表项上添加这个水平自定义菜单?

这是我到目前为止所得到的.

@Override      
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    LayoutInflater inflater = getLayoutInflater().from(this);
    View view = inflater.inflate(R.layout.custom_listview, null, false);
    menu.setHeaderView(view);
    menu.add("Delete");
    menu.add("Edit");
}

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    int position = info.position;
    View v = listView.getChildAt(position);
    TextView typeTv = v.findViewById(R.id.custom_listview_type);
    TextView userTv = v.findViewById(R.id.custom_listview_user);
    TextView passTv = v.findViewById(R.id.custom_listview_password);

    if (item.getTitle().equals("Delete")) {
        db.execSQL("delete from user_added_accounts where accountType = '" + typeTv.getText().toString() …
Run Code Online (Sandbox Code Playgroud)

java android contextmenu

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

无法从 Android 应用程序连接到 localhost API

我是 Django 的新手。我创建了一个名为 API 的 API http://127.0.0.1:8000/api/update/1/,它可以在浏览器和 Postman 应用程序中完美运行。

但是,当我尝试从 Android 应用程序访问 API 时,它返回 NULL。

当 API 如下时,android 代码有效。

http://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=8190df9eb51445228e397e4185311a66
Run Code Online (Sandbox Code Playgroud)

但是,当 API 如下时它不起作用,即使以下 API 在我在同一台 PC 上运行的浏览器和 Postman 应用程序中工作得很好。

http://127.0.0.1:8000/api/update/1/
Run Code Online (Sandbox Code Playgroud)

我附上了进行 API 调用的代码。

protected String doInBackground(String... args) {
    String xml = "";
    String api = "http://127.0.0.1:8000/api/update/1/"; // returns NULL works in Postman app and in the browser
    // String api = "http://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey=8190df9eb51445228e397e4185311a66"; // works in all places
    String urlParameters = "";
    xml = Function.excuteGet(api, urlParameters);
    return  xml;
}
Run Code Online (Sandbox Code Playgroud)

谁能帮我这个?提前致谢。

java api django android localhost

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

在android中设置proguard规则,它只能加密代码吗?

我在我的应用程序使用的几个库和之后的minifyEnabledtrue,它不能生成APK.经过一些研究,我找到了规则并将其.pro逐个添加到文件中.

这是图书馆清单

compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.squareup.picasso:picasso:2.3.2'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5@aar'
compile 'org.apache.httpcomponents:httpmime:4.3.5'//Volley
compile 'org.apache.httpcomponents:httpcore:4.2.4'//Volley
compile 'com.mcxiaoke.volley:library:1.0.17'//Volley
compile 'com.github.bumptech.glide:glide:3.6.1'//Gradle
compile 'com.baoyz.swipemenulistview:library:1.3.0'//Swipe Menu li stview
compile 'org.lucasr.twowayview:twowayview:0.1.4' //horizontal listview
compile 'com.android.support:recyclerview-v7:+'
Run Code Online (Sandbox Code Playgroud)

对于JAR,它是 PayPalAndroidSDK-2.9.11.jar

简而言之,我想知道是不是可以不为库添加规则,因为有些库似乎没有提到如何为它们设置proguard?它可以加密而不是优化代码并删除一些有用的代码吗?

非常感谢.

java android proguard android-proguard

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