我想知道是否有办法在Android中以编程方式阅读手机模型.
我想得到像HTC Dream,Milestone,Sapphire或其他任何东西......
我正在使用输入框AlertDialog.在EditText该对话框中本身自动对焦,当我打电话AlertDialog.show(),但软键盘未自动显示.
如何在显示对话框时自动显示软键盘?(并且没有物理/硬件键盘).与按下"搜索"按钮调用全局搜索的方式类似,将自动显示软键盘.
从文档开始:
public void setRetainInstance(boolean retain)
控制是否在活动重新创建(例如从配置更改)中保留片段实例.这只能用于不在后栈中的片段.如果设置,则在重新创建活动时,片段生命周期会略有不同:
- onDestroy()不会被调用(但是onDetach()仍然会被调用,因为片段正在与其当前活动分离.
- 因为片段没有被重新创建,所以不会调用onCreate(Bundle).
- onAttach(Activity)和onActivityCreated(Bundle)仍将被调用.
我有一些问题:
片段是否也保留其视图,还是会在配置更改时重新创建?"保留"究竟是什么意思?
当用户离开活动时,片段是否会被销毁?
为什么它不适用于后端堆栈上的碎片?
哪个是使用此方法有意义的用例?
使用带有gradle插件版本的Android Studio 3.3 Canary 11 3.3.0-alpha11.尝试同步gradle时,它会引发以下错误
WARNING: API 'variant.getExternalNativeBuildTasks()' is obsolete and has been
replaced with 'variant.getExternalNativeBuildProviders()'.
It will be removed at the end of 2019.
For more information, see https://d.android.com/r/tools/task-configuration-
avoidance
Affected Modules: app
Run Code Online (Sandbox Code Playgroud)
单击错误会将我引导至gradle文件中的此行
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "${variant.name}-${variant.versionName}.apk"
}
}
Run Code Online (Sandbox Code Playgroud)
我到底需要改变什么?
项目 build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
mavenCentral() // jcenter() works as well because it pulls from …Run Code Online (Sandbox Code Playgroud) android firebase android-studio android-gradle-plugin fabric.io
当设备在Android上启动时,我一直在尝试启动服务,但我无法让它工作.我在网上看了很多链接,但没有一个代码可以工作.我忘记了什么吗?
<receiver
android:name=".StartServiceAtBootReceiver"
android:enabled="true"
android:exported="false"
android:label="StartServiceAtBootReceiver" >
<intent-filter>
<action android:name="android.intent.action._BOOT_COMPLETED" />
</intent-filter>
</receiver>
<service
android:name="com.test.RunService"
android:enabled="true" />
Run Code Online (Sandbox Code Playgroud)
public void onReceive(Context context, Intent intent) {
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
Intent serviceLauncher = new Intent(context, RunService.class);
context.startService(serviceLauncher);
Log.v("TEST", "Service loaded at start");
}
}
Run Code Online (Sandbox Code Playgroud) 我想将 jitpack.io 添加为我的 gradle 文件中的存储库。这是我的 gradle 根文件:
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:7.0.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.21"
classpath 'com.google.dagger:hilt-android-gradle-plugin:2.38.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)
由于我没有“allrepositories”来放置我的依赖项(仅适用于那里),因此我在 buildscript 代码之后创建并添加了此代码:
allprojects {
repositories {
maven {url 'https://www.jitpack.io'}
}
}
Run Code Online (Sandbox Code Playgroud)
但这是我得到的错误
Caused by: org.gradle.api.InvalidUserCodeException: Build was configured to prefer settings repositories over project repositories but repository 'maven' was added …Run Code Online (Sandbox Code Playgroud) 我使用线性布局来显示非常轻的初始屏幕.它有一个按钮,应该在屏幕中水平和垂直居中.但无论我尝试做什么,按钮都会在顶部对齐中心.我已经包含了下面的XML,有人能指出我正确的方向吗?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton android:id="@+id/btnFindMe"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:background="@drawable/findme"></ImageButton>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud) 我知道这是一个非常基本的问题,但令我惊讶的是,我找不到任何关于Android SDK Build-tools的文档.除了Android SDK工具和Android SDK平台工具之外,还有一堆Android SDK Build-tools,如附图所示.任何人都可以指向一个解释所有这些内容的来源,并帮助澄清如何选择某个版本的Android SDK Build-tools使用?

编辑(2014-02-27):
我仍然不完全了解所有工具.以下是基于Google最新文档的有限理解:
我仍然不明白从Android SDK平台工具中获取Android SDK Build-tools的理由,这些工具具有单个实例并且易于管理更新.我能想到的唯一可能的原因是某些应用程序必须依赖较旧的构建组件来构建它们.谷歌的文件提到了这一点,但没有解释原因.查看发行说明,您会注意到Android SDK Build-tools的更新主要用于修复错误或/添加对新平台的支持.我可以想到一些应用程序使用旧版Android SDK Build-tools的唯一原因是它们依赖于Android SDK Build-tools的某些缺陷.如果没有使用这些错误构建,这些应用程序将无法正常运行.我希望Google能够通过提供一两个示例来更好地解释这一点,这些示例说明了为什么这些工具中的错误对某些应用程序至关重要
我有一个带有menuitem的操作栏.如何隐藏/显示该菜单项?
这就是我想要做的:
MenuItem item = (MenuItem) findViewById(R.id.addAction);
item.setVisible(false);
this.invalidateOptionsMenu();
Run Code Online (Sandbox Code Playgroud) 我有一个带有三个标签的应用程序.
每个选项卡都有自己的布局.xml文件.main.xml有自己的地图片段.这是应用程序首次启动时显示的那个.
除了在标签之间切换时,一切正常.如果我尝试切换回地图片段选项卡,我会收到此错误.切换到其他选项卡之间和之间的工作正常.
这可能有什么问题?
这是我的主类和我的main.xml,以及我使用的相关类(你也会在底部找到错误日志)
主要班级
package com.nfc.demo;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.Toast;
public class NFCDemoActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ActionBar bar = getActionBar();
bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
bar.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
bar.addTab(bar
.newTab()
.setText("Map")
.setTabListener(
new TabListener<MapFragment>(this, "map",
MapFragment.class)));
bar.addTab(bar
.newTab()
.setText("Settings")
.setTabListener(
new TabListener<SettingsFragment>(this, "settings",
SettingsFragment.class)));
bar.addTab(bar
.newTab()
.setText("About")
.setTabListener(
new TabListener<AboutFragment>(this, "about",
AboutFragment.class)));
if (savedInstanceState != null) {
bar.setSelectedNavigationItem(savedInstanceState.getInt("tab", 0));
}
// setContentView(R.layout.main);
}
@Override
protected void onSaveInstanceState(Bundle …Run Code Online (Sandbox Code Playgroud) android illegalargumentexception android-maps android-fragments