小编kar*_*ran的帖子

Logcat没有显示任何内容

我正在研究我的android应用程序并使用eclipse构建它并在android logcat中显示一些值.

一切都工作正常但突然现在当我运行我的应用程序logcat没有显示任何now.i也尝试运行我的其他应用程序但仍然是空白.

这种行为的原因是什么,我怎样才能让它重新恢复工作?

eclipse android android-logcat

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

了解fflush()的必要性以及与之相关的问题

以下是使用fflush()的示例代码:

#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <io.h>

void flush(FILE *stream);

int main(void)
{
   FILE *stream;
   char msg[] = "This is a test";

   /* create a file */
   stream = fopen("DUMMY.FIL", "w");

   /* write some data to the file */
   fwrite(msg, strlen(msg), 1, stream);

   clrscr();
   printf("Press any key to flush DUMMY.FIL:");
   getch();

   /* flush the data to DUMMY.FIL without closing it */
   flush(stream);

   printf("\nFile was flushed, Press any key to quit:");
   getch();
   return 0;
}

void flush(FILE *stream)
{ …
Run Code Online (Sandbox Code Playgroud)

c fflush

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

R.java文件实际上做了什么以及如何做

我一直在研究一个简单的android教程,在浏览项目文件夹时,我R.javagen文件夹中找到了这个文件...

当我打开它时,我觉得一团糟......

  • 首先R是一个class.
  • multiple Inner classes内如定义drawable,id,layout等.
  • 并且内部类有很多变量声明如下,并用十六进制值分配

    public static final int addr = 0x7f080003; ... ... 以及更多

R是自动生成的,并充当其他文件的指针

R.java的问题

  • 什么是基本的
  • 这个怎么运作
  • 为什么
  • 值以十六进制表示
  • 在实际应用程序运行时它执行了什么角色

android

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

滚动时折叠工具栏不会折叠

我正在尝试在我的 android 应用程序中实现折叠工具栏。我可以按照我想要的方式显示工具栏,但是当我滚动时它不会折叠。

我正在使用下面的代码

活动.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context=".MainActivity">

<include layout="@layout/main_toolbar" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <com.gigamole.navigationtabstrip.NavigationTabStrip
        android:id="@+id/nts_strip"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        app:nts_active_color="@color/white"
        app:nts_animation_duration="300"
        app:nts_color="@color/white"
        app:nts_corners_radius="1.5dp"
        app:nts_inactive_color="@color/white_transparent"
        app:nts_titles="@array/nts_titles" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager_photos"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="@color/white_transparent" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

main_toolbar.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:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_collapseMode="parallax"
android:orientation="vertical">

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsingToolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

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

            <TextView
                android:id="@+id/tv_toolbar_title"
                android:layout_width="match_parent"
                android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout android-collapsingtoolbarlayout

7
推荐指数
1
解决办法
5040
查看次数

从Android应用程序点击按钮更改android手机的系统日期

我正在尝试使用android的一些东西,因为我正在学习android开发,现在我有一个场景.

  • 我想通过我的应用程序更改android手机的系统日期(首先我想知道这是可行的吗?)

布局如下

布局

现在我想要的是当用户点击按钮时,日期应该增加20天,我该怎么做.

我无法开始......请帮助

android date

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

如何将我的Spinner显示在工具栏的右侧

我的布局如下所示 在此输入图像描述

您可以看到微调器添加到我的工具栏中,但我想要的是使其正确对齐,将其显示在工具栏的最右侧.

下面是我使用的xml代码

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:elevation="4dp"
            android:gravity="right"                          //gravity set to right
            android:background = "@color/color_toolbar"
        >
             <Spinner
                android:id="@+id/spinner_category"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </android.support.v7.widget.Toolbar> 
   </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

旋转器没有显示 android:layout_gravity 在此输入图像描述 我尝试将重力设置为正确,但它不起作用.我怎样才能做到这一点?

android android-spinner android-toolbar

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

无法在当前主题中找到“?attr/textAppearanceCaption”

这是我的简单 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
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:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
    android:id="@+id/main_screen"
    android:layout_width="match_parent"
    android:layout_height="593dp"
    android:background="@color/CadetBlue"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.0">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
    android:id="@+id/bottom_menu"
    style="@style/Widget.MaterialComponents.BottomNavigationView.Colored"
    android:layout_width="match_parent"
    android:layout_height="67dp"
    android:layout_alignParentBottom="true"
    android:baselineAligned="false"
    app:itemBackground="@color/colorPrimary1"
    app:itemIconTint="@drawable/item_selector"
    app:itemTextColor="@drawable/item_selector"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/main_screen"
    app:menu="@menu/nav_items" />
Run Code Online (Sandbox Code Playgroud)

我的 build.gradle 文件是

    //noinspection GradleCompatible
   apply plugin: 'com.android.application'

   android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.smile_sifat.donatethefloody"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner 
       "android.support.test.runner.AndroidJUnitRunner"
       }
       buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 
     'proguard-rules.pro'
        }
    } …
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
7584
查看次数

使用带有警报对话框的最新材料概述按钮

我想使用带有默认警报对话框的新材料轮廓按钮。

我在style.xml中创建了样式,如下所示

<style name="OutlinedButton" parent="Widget.MaterialComponents.Button.TextButton">
    <item name="strokeColor">@color/colorAccent</item>
    <item name="strokeWidth">2dp</item>
</style>

<style name="MaterialDialogStyle" parent="Theme.MaterialComponents.Dialog.Alert">
    <item name="android:textColorPrimary">@color/colorAccent</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="colorPrimary">@color/colorAccent</item>
    <item name="buttonStyle">@style/OutlinedButton</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我正在使用新的 Material Components 主题来设置“是”和“否”按钮的样式。

现在,我通过将其设置为 AlertDialog 构建器来在代码中使用上述样式。

AlertDialog.Builder builder = new AlertDialog.Builder(ProductListActivity.this, R.style.MaterialDialogStyle);
Run Code Online (Sandbox Code Playgroud)

但输出如下 在此输入图像描述

有没有办法将最新材料概述按钮与默认警报对话框一起使用?如果有什么区别的话,我正在使用设计支持库中的材料组件。

android android-alertdialog android-styles material-design material-components-android

5
推荐指数
1
解决办法
2512
查看次数

Android 9.0以下版本如何使用生物识别提示API

我正在尝试实施生物识别提示 API 以使用指纹验证对用户进行身份验证。我成功地集成了生物识别提示,它正在 andorid 9.0 上运行。但正如文档所示,生物识别 api 也向后兼容,但是当我使用下面的代码构建对话框时,它会显示 API 支持警告。

调用需要 API 级别 28(当前最低为 15):new android.hardware.biometrics.BiometricPrompt.Builder less... (Ctrl+F1) 此检查会扫描应用程序中的所有 Android API 调用,并警告任何以下调用:不适用于此应用程序的所有目标版本(根据清单中的最小 SDK 属性)

mBiometricPrompt = new BiometricPrompt.Builder(this)
                        .setDescription("Description")
                        .setTitle("Title")
                        .setSubtitle("Subtitle")
                        .setNegativeButton("Cancel", getMainExecutor(), new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                Log.i(TAG, "Cancel button clicked");
                            }
                        })
                        .build();
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能使其在较低的 api 上工作?这是屏幕截图。 在此输入图像描述

android android-fingerprint-api

5
推荐指数
1
解决办法
6949
查看次数

在中心显示回收器中的最后一个项目

我的 RecyclerView 有 2 列。我想要的是如果列表中的项目数为奇数,则显示中心的最后一个项目。像这样的东西

在此输入图像描述

我尝试从这里实现所有 so 线程https://www.google.com/search?client=firefox-bd&q=show+last+item+in+recyclerview+center+horizo ​​ntal+android

我使用下面的代码来设置布局管理器

    gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
        @Override
        public int getSpanSize(int position) {
            if (mLangInfos.size() % 2 == 0)
                return 1;
            else {
                if (position == mLangInfos.size()-1)
                    return 2;
                else
                    return 1;
            }
        }
    });
    recyclerView.setLayoutManager(gridLayoutManager);
Run Code Online (Sandbox Code Playgroud)

但这的作用是它以全角显示最后一个项目,请参见下图。

在此输入图像描述

android gridlayoutmanager android-recyclerview

5
推荐指数
0
解决办法
1027
查看次数