Questions tagged «android»

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

7
向ListView的最后一个元素添加下边距
我需要添加添加具有复杂项目背景的ListView:顶部和底部的偶数/奇数和圆角不同。看起来像这样: 我已经通过级别列表实现了所有这些东西,但是我还想做一件事。现在,底部项目位于屏幕底部附近。最好增加一些空间。 我不想在ListView中添加底边距,我只需要为最后一项添加边距。 我看到的方法是: 页脚 一种技巧–将带有空白TextView的页脚添加到ListView。但是页脚是非常不稳定的东西,它们通常在notifyDataSetChanged之后消失,并且没有办法将它们恢复 具有透明像素的图像 我要求设计师将透明像素添加到底部背景资源。不幸的是,在这种情况下,垂直居中被完全破坏了。例如,有9patch这样的: 布局如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <!-- View with background with transparent pixels on bottom --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/item" android:background="@drawable/some_bgr" android:padding="10dp" > <TextView android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Title" android:layout_gravity="center" android:textSize="18sp" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Detail" android:layout_gravity="center" android:textSize="18sp" /> </LinearLayout> …

17
这是什么意思“找不到启动器活动!”
我正在编写一个简单的Android程序,但没有得到这些错误,我不知道它们是什么。我的程序是正确的,但未显示输出。我认为是因为这两行: [2005-01-06 19:56:38 - my_Android] No Launcher activity found! [2005-01-06 19:56:38 - my_Android] The launch will only sync the application package on the device!
82 android  eclipse 

8
如何更改TextView的边距
我已经以编程方式将TextView添加到LinearLayout中,并且在某些外部事件中,我想将TextView的底部边距减小到-10,为此我尝试了以下操作。 LinearLayout.LayoutParams lastTxtParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); lastTxtParams.setMargins(0, 0, 0, -10); mOldTextView.setLayoutParams(lastTxtParams); mOldTextView.invalidate(); 修改已添加到视图的小部件边距的正确方法是正确的吗? 有些不起作用。
82 android 

3
如何在操作栏上添加下拉菜单项
在我的Android Honeycomb应用程序中,我使用Tabs作为导航样式。我想在溢出按钮旁边添加一个项目,但是我希望该项目成为一个下拉列表,并且用户可以在那里选择一个选项,但与导航无关。自从我使用以来,最简单的方法是什么mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 是否可以在不使用自定义视图的情况下做到这一点?

11
Android:对话框中的EditText不会弹出软键盘
因此,我遇到了一个常见问题,那就是对话框中的EditText在获得焦点时没有显示。我已经看到了几种变通方法,例如在该线程,这个和这个(以及更多)中,但是我从来没有见过令人满意的解释,为什么会首先发生这种情况。 我更希望让android使用自己的默认行为来编辑文本而不是构建自己的默认行为,但是似乎每个人(在那些线程中)都已经接受了Dialogs中的EditTexts的默认行为是仅提供光标而没有键盘。为什么会这样呢? 记录下来,这些变通办法似乎都不对我有用-我能够获得的最接近的结果是强制键盘出现在对话框下面(使用InputMethodManager.toggleSoftKeyboard(*))。我的特定配置是API15,EditText显示在AlertDialog中ListView的页脚中。设置了EditText android:focusable =“ true”,并且onFocusChangeListener正在接收焦点事件。 编辑: 根据要求,这是我正在使用的特定代码段。我不会打扰整个布局,但是在这个特定的应用程序中,EditText的出现是响应按下对话框上的按钮(类似于动作视图)。它包含在RelativeLayout中,默认情况下其可见性为“ gone”: <RelativeLayout android:id="@+id/relLay" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerVertical="true" android:visibility="gone" android:layout_marginTop="5dp" android:layout_marginBottom="5dp"> <ImageButton android:id="@+id/cancelBut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:background="@color/transparent" android:src="@drawable/cancelButton" android:layout_margin="5dp"/> <ImageButton android:id="@+id/okBut" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toLeftOf="@id/cancelBut" android:background="@color/transparent" android:src="@drawable/okButton" android:layout_margin="5dp" /> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="text" android:focusable="true" android:layout_toLeftOf="@id/okBut"/> </RelativeLayout> 生成此代码的代码将relativeLayout的可见性设置为“ Visible”(并隐藏其他UI元素)。这应该是足够的,当得到的EditText重点,根据我的EditText经验拉起键盘。但是,由于某些原因,情况并非如此。我可以设置以下onFocusChangeListener: edit_text.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void …

10
Android:如何以编程方式启用/禁用Wifi或Internet连接
使用连接管理器类,我们可以访问wifi或Internet网络: ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE); // ARE WE CONNECTED TO THE NET if ( connec.getNetworkInfo(0).getState() == NetworkInfo.State.CONNECTED || connec.getNetworkInfo(1).getState() == NetworkInfo.State.CONNECTED ) { // ... } 其中0和1分别指的是移动和wifi连接 如果我的Android设备同时连接到这两个设备,我们可以在任何网络之间切换还是可以禁用任何网络?就像使用一个函数: connec.getNetworkInfo(0).setState(NetworkInfo.State.DISCONNECTED);
82 android 

26
无法在Android上加载libGL.so
我将Ubuntu 12.04(精确的穿山甲)与Oracle JDK 7配合使用,当我从Eclipse运行Android模拟器时,出现此错误: [2012-07-04 02:52:10 - Emulator] error libGL.so: cannot open shared object file: No such file or directory [2012-07-04 02:52:10 - Emulator] Failed to load libGL.so 模拟器也很慢。我怎么解决这个问题?
82 android 

22
Android Studio:Gradle-构建失败-任务':dexDebug'的执行失败
错误: Gradle: Execution failed for task ':vertretungsplan:dexDebug'. > Failed to run command: P:\Android-Studio\sdk\build-tools\18.0.1\dx.bat --dex --output P:\Projekte\VertretungsplanProject\vertretungsplan\build\libs\vertretungsplan-debug.dex P:\Projekte\VertretungsplanProject\vertretungsplan\build\classes\debug P:\Projekte\VertretungsplanProject\vertretungsplan\build\dependency-cache\debug P:\Android-Studio\sdk\extras\android\m2repository\com\android\support\support-v4\18.0.0\support-v4-18.0.0.jar P:\Projekte\VertretungsplanProject\vertretungsplan\libs\commons-io-2.4.jar P:\Projekte\VertretungsplanProject\vertretungsplan\build\exploded-bundles\VertretungsplanProjectLibrariesActionbarsherlockUnspecified.aar\classes.jar Error Code: 2 Output: trouble processing: bad class file magic (cafebabe) or version (0033.0000) ...while parsing de/MayerhoferSimon/Vertretungsplan/LoginActivity$2.class ...while processing de/MayerhoferSimon/Vertretungsplan/LoginActivity$2.class trouble processing: bad class file magic (cafebabe) or version …

30
无法实例化android.gms.maps.MapFragment
我尝试通过非常简单的活动使用Google Maps android v2进行演示,只需从Google页面复制代码即可:https : //developers.google.com/maps/documentation/android/start#adding_the_api_key_to_your_application 活动: package com.example.mapdemo; import android.app.Activity; import android.os.Bundle; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } } 用于布局: <?xml version="1.0" encoding="utf-8"?> <fragment xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" class="com.google.android.gms.maps.MapFragment"/> 我已经根据页面申请了一个api密钥并修改了我的androidmanifest.xml文件,就像这样: <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.wenhai.driverschool" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="15" /> …

17
从onActivityResult显示DialogFragment
我的onActivityResult中有以下代码用于我的片段: onActivityResult(int requestCode, int resultCode, Intent data){ //other code ProgressFragment progFragment = new ProgressFragment(); progFragment.show(getActivity().getSupportFragmentManager(), PROG_DIALOG_TAG); // other code } 但是,出现以下错误: Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState 有人知道怎么回事,或者我怎么解决这个问题?我应该注意我正在使用Android支持包。

14
Android Studio-超出预期的最高级别:
我已使用该工具提供的新项目模板在Android Studio中构建了一个新项目。所有代码均由Studio生成,我尚未进行任何修改。 我正在尝试运行代码,但应用程序失败并出现以下错误,不确定是什么问题,因此感谢您的帮助。 UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Landroid/support/v7/app/ActionBar$Callback; at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103) FAILED FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:dexDebug'. > com.android.ide.common.internal.LoggedErrorException: …

15
Android Activity ClassNotFoundException-尝试了一切
我刚刚将应用程序重构为框架库和应用程序,但是现在当我尝试在模拟器中启动该应用程序时,我得到了以下错误堆栈跟踪: 06-02 18:22:35.529: E/AndroidRuntime(586): FATAL EXCEPTION: main 06-02 18:22:35.529: E/AndroidRuntime(586): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.matthewrathbone.eastersays/com.matthewrathbone.eastersays.EasterSimonSaysActivity}: java.lang.ClassNotFoundException: com.matthewrathbone.eastersays.EasterSimonSaysActivity in loader dalvik.system.PathClassLoader[/data/app/com.matthewrathbone.eastersays-1.apk] 06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585) 06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679) 06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread.access$2300(ActivityThread.java:125) 06-02 18:22:35.529: E/AndroidRuntime(586): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033) 06-02 18:22:35.529: E/AndroidRuntime(586): at android.os.Handler.dispatchMessage(Handler.java:99) 06-02 18:22:35.529: E/AndroidRuntime(586): at …

1
Android:捕获活动的返回
我对启动新活动有疑问。归结为这一点。我在视图上有3个标签 A) contains gMap activity B) camera activity C) some random text fields. 要求是应用程序以纵向模式运行。 除Camera Preview Surface(B)以外,所有3个选项卡均可按预期工作。将其旋转90度。他们唯一能使它正确的方法是将应用程序设置为横向模式,从而使我的所有选项卡乱七八糟,几乎是行不通的。 我的解决方案是:替换 我的相机活动中有一个常规活动为空,但没有 Intent i = new Intent(this,CameraActivity.class); startActivity(i); 这将启动我的CameraActivity。那很好。我必须进行线性布局,并包含3张看起来像真实标签的图像,因此我可以尝试模拟标签的操作,同时将屏幕旋转为横向,并使视觉效果保持为纵向。用户可以单击其中一个图像(按钮)以显示下一个选项卡。这是我的问题。它应退出我的“相机活动”,然后返回至标签中的“空白活动”,在此处应解释为单击图像中所需的标签。 最主要的是,当它返回时,它返回到选项卡下的空白(黑色)页面(因为它是“空”)。如何将返回事件捕获回到调用该活动的页面,然后查看它们执行了什么操作? 我可以设置一个onclicklistener,在其中我可以响应单击的假标签(图像)退出相机活动。退出时,标签应更新,以便您返回。有什么建议么? 谢谢,

13
找不到Android Studio Gradle DSL方法:“ android()”-错误(17,0)
我试图在Android Studio中运行我的项目,但错误出现在下面: 我已经跟踪了许多消息来源,只是想让它运行起来并在这里结束,但是不知道该怎么办。 如何配置该项目以运行? build.gradle: // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:0.9.+' } } allprojects { repositories { mavenCentral() } } android { compileSdkVersion 19 buildToolsVersion "19.1" } settings.gradle: include ':app' local.properties: sdk.dir=C\:\\Users\\KJA\\AppData\\Local\\Android\\sdk …


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.