Questions tagged «android»

Android是Google的移动操作系统,用于对数字设备(智能手机,平板电脑,汽车,电视,Wear,Glass和IoT)进行编程或开发。对于与Android相关的主题,请使用特定于Android的标签,例如android-intent,android-activity,android-adapter等。对于与开发或编程无关但与Android框架相关的问题,请使用以下链接:https:// android.stackexchange.com。


13
命令行中的Android Stop Emulator
这个问题与如何通过命令行关闭Android仿真器相同。 但是,从第一个答案尝试建议的解决方案后,adb emu kill对我而言并没有证明是成功的。 我正在为Android应用程序自动化单元测试。我的bash脚本在无头计算机上运行。它使用创建一个android设备android create avd并emulator使用-no-window属性执行。然后,它编译测试项目,使用连接到仿真器adb,安装项目并执行我的测试。这一切都很好。 现在,我需要终止仿真器过程,就像引用的帖子一样,我只能使用来执行此操作kill -9。 Google的“从命令行管理AVD ”教程只提到了如何在GUI环境中停止模拟器。 任何帮助表示赞赏。


20
ActivityCompat.requestPermissions不显示对话框
if (ContextCompat.checkSelfPermission(RegisterActivity.this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_DENIED){ ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_PHONE_STATE}, REQUEST_READ_PHONE_STATE_PERMISSION); 我正在尝试在nexus 5 api 23上使用此功能,它只是不向我显示对话框,如它应该做的那样,它什么也没做。是什么原因引起的?(此代码在Java活动中)我尝试将最低api更改为23,并在没有ActivityCompat的情况下使用requestPermissions(),但仍然无法正常工作。 apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.example.idanayzen.photomap" minSdkVersion 23 targetSdkVersion 23 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile …

6
如何正确设置Android的行高?
我是UX架构师,与一群初级的Android开发人员一起工作。我们在Android中正确设置行高时遇到问题。 我们正在使用材料设计规范作为我们应用的指南。特别是,您可以在此处查看线​​高规格: https://material.google.com/style/typography.html#typography-line-height 让我们以Body 2为例。规范说类型是13sp或14sp,而前导(线高-同样)应为24dp。 这就是问题所在:这些开发人员告诉我,无法像代码中那样设置行高。相反,他们告诉我测量文本两行之间的距离,并给他们测量该距离-假设它是4dp。他们想要我们正在使用的每种样式的文本。 我们使用“草图> Zepelin流”作为规格。 对于我来说,能够创建带有24dp开头的13sp的字体样式(在代码中可以很容易地成为类/样式)对我来说似乎很奇怪,而不能设置开头,而是必须添加第三个度量来混合。在Sketch或Zepelin中,“线之间”没有这样的位置。 这真的是完成的方式吗,还是有设置线高的适当方法?

24
无法创建类ViewModel的实例
我正在尝试使用Android体系结构组件编写示例应用程序,但是即使尝试了几天,我仍然无法使它正常工作。它给了我上面的例外。 生命周期所有者:- public class MainActivity extends LifecycleActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView textView = findViewById(R.id.tv_user); PostViewModel viewModel = ViewModelProviders.of(this).get(PostViewModel.class); viewModel.loadPosts(); viewModel.getPost().observe(this, new Observer<Post>() { @Override public void onChanged(@Nullable Post post) { if(post != null) { textView.setText(post.toString()); } } }); } } ViewModel:- public class PostViewModel extends …

6
Android:在应用被杀死时保持服务运行
IntentService即使应用被杀死,我也希望在后台继续运行。“杀死”的意思是长时间按主页按钮->查看所有正在运行的应用程序->将我的应用程序滑到一边->应用程序被杀死,或者长时间按后退按钮->应用程序被杀死 我的代码如下。在我的MainActivity中: Intent intent = new Intent(this, MyService.class); this.startService(intent); 在我的MyService中: public class MyService extends IntentService { @Override protected void onHandleIntent(Intent intent) { System.out.println("MyService started"); run(); } private void run() { while (true){ System.out.println("MyService still running"); doSomething(); waitSomeTime(); } } } 打开应用程序后,我看到该服务正在运行。通过主页按钮最小化应用程序时,它仍在运行。通过后退按钮关闭应用程序时,它仍在运行。但是,如果我如上所述杀死它,它将停止。我该如何解决?




5
Android Gradle在APK META-INF / license.txt中复制的文件重复
我将通过Spring将RESTful Web Service支持添加到我的Android应用程序,如此处https://spring.io/guides/gs/using-rest-android/所述。 这是顶级build.gradle配置: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.1.0' } } allprojects { repositories { jcenter() } } 这是我的app/build.gradle配置: apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0.3" defaultConfig { applicationId …

6
如何将填充分配给Listview项目分隔线
当我在图像中显示时,如何给列表项添加填充。我想在布局中制作分隔线,如图所示。 这是我的列表片段代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginLeft="25dp" android:layout_marginRight="25dp"> <ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/listV_main" android:layout_marginLeft="25dp" android:layout_marginRight="25dp"/> 这是我的列表部分代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingLeft="10dp" android:paddingTop="10dp" android:paddingRight="10dp" android:paddingBottom="10dp"> <include android:id="@+id/list_item_section_text" layout="@android:layout/preference_category" /> 这是我的清单项目代码 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:minHeight="?android:attr/listPreferredItemHeight" android:adjustViewBounds="true" android:paddingRight="?android:attr/scrollbarSize" > <ImageView android:id="@+id/showlist_item_entry_drawable" android:layout_width="82dp" android:adjustViewBounds="true" android:layout_height="68dp" android:scaleType="fitXY" android:paddingLeft="9dp"/> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="10dip" android:layout_marginRight="6dip" …

6
Android Studio中的JNI和Gradle
我正在尝试将本机代码添加到我的应用中。我拥有../main/jni了Eclipse项目中的所有内容。我已添加ndk.dir=...到local.properties。我还没有做其他任何事情(我不确定实际上还需要什么,所以如果我错过了什么,请告诉我)。当我尝试构建时,出现以下错误: Execution failed for task ':app:compileDebugNdk'. > com.android.ide.common.internal.LoggedErrorException: Failed to run command: /Users/me/android-ndk-r8e/ndk-build NDK_PROJECT_PATH=null APP_BUILD_SCRIPT=/Users/me/Project/app/build/ndk/debug/Android.mk APP_PLATFORM=android-19 NDK_OUT=/Users/me/Project/app/build/ndk/debug/obj NDK_LIBS_OUT=/Users/me/Project/app/build/ndk/debug/lib APP_ABI=all Error Code: 2 Output: make: *** No rule to make target `/Users/me/Project/webapp/build/ndk/debug//Users/me/Project/app/src/main/jni/jni_part.cpp', needed by `/Users/me/Project/app/build/ndk/debug/obj/local/armeabi-v7a/objs/webapp//Users/me/Project/app/src/main/jni/jni_part.o'. Stop. 我需要做什么? Android.mk: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) # OpenCV OPENCV_CAMERA_MODULES:=on OPENCV_INSTALL_MODULES:=on include .../OpenCV-2.4.5-android-sdk/sdk/native/jni/OpenCV.mk LOCAL_MODULE …

8
Android材质设计按钮-预棒棒糖
如何实现Google的材料设计指南中所述的“凸起按钮”和“扁平按钮”? 凸起的按钮为大多数平面布局增加了尺寸。他们强调在繁忙或宽敞的空间上的功能。 为工具栏和对话框使用平面按钮,以避免过多的分层。 来源:http://www.google.com/design/spec/components/buttons.html

12
强制应用程序在第一次活动时重新启动
由于未知的原因,我无法正常退出应用程序,因此再次按下主屏幕按钮和应用程序图标时,我将恢复在应用程序中的位置。我想强制应用程序在第一个活动上重新启动。 我想这与onDestroy()或也许onPause()有关,但是我不知道该怎么办。
75 android 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.