Questions tagged «android»

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

8
了解RecyclerView setHasFixedSize
我在理解上有些困难setHasFixedSize()。我知道RecyclerView文档中的大小不变时,它用于优化。 那是什么意思呢?在大多数情况下,ListView尺寸几乎总是固定的。在什么情况下不是固定大小?这是否意味着它在屏幕上占据的实际空间会随着内容的增长而增加?

5
android中adjustResize和adjustPan之间的区别?
我试图编写一个代码,该代码用于在软键盘出现时重新调整UI组件的大小。当我使用adjustResize时,它会调整UI组件的大小,同时AdjustPan给我相同的输出。我想知道它们之间的区别以及何时使用每个组件?哪一个(adjustPan或AdjustResize)适合调整UI大小? 这是我的xml: <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true" > <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="vertical" > <EditText android:id="@+id/editText5" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="45dp" android:ems="10" android:inputType="textPersonName" /> <Button android:id="@+id/button1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="40dp" android:text="My Button" /> </LinearLayout> </RelativeLayout> </ScrollView> 和清单文件: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.adjustscroll" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17" …

7
如何处理活动中的后退按钮
如何处理活动中的后退按钮?我有一些按钮。如果单击按钮之一,它将重定向到我需要的按钮。它工作正常,但是当我按返回按钮时,它就完成了。 如何解决这个问题呢。我所有这些按钮只有一个活动。提前致谢。 @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if ((keyCode == KeyEvent.KEYCODE_BACK)) { return false; //I have tried here true also } return super.onKeyDown(keyCode, event); } 我已经使用上面的代码来处理后退按钮,但它不起作用。当我按下后退按钮时,它本身就击中了。
136 android 

9
使用LinearLayout将按钮放在屏幕底部吗?
我有以下代码,如何使3个按钮位于底部? <TextView android:id="@+id/textView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="60dp" android:gravity="center" android:text="@string/observer" android:textAppearance="?android:attr/textAppearanceLarge" tools:context=".asdf" android:weight="1" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/button1" style="?android:attr/buttonStyleSmall" android:layout_width="145dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|center" android:text="1" /> <Button android:id="@+id/button2" style="?android:attr/buttonStyleSmall" android:layout_width="145dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|center" android:text="2" /> <Button android:id="@+id/button3" style="?android:attr/buttonStyleSmall" android:layout_width="145dp" android:layout_height="wrap_content" android:layout_gravity="center_horizontal|center" android:text="3" /> </LinearLayout>

10
Android TextView:“不要连接使用setText显示的文本”
我通过以下方式使用setText()设置文本。 prodNameView.setText("" + name); prodOriginalPriceView.setText("" + String.format(getString(R.string.string_product_rate_with_ruppe_sign), "" + new BigDecimal(price).setScale(2, RoundingMode.UP))); 因为第一个是简单的用法,第二个是使用格式化文本设置文本。 Android Studio非常有趣,我使用了Menu,Analyze -> Code Cleanup并且在上面两行得到了建议。 不要连接使用setText显示的文本。将资源字符串与占位符一起使用。更少...(Ctrl + F1) 调用TextView#setText时: 永远不要调用Number#toString()格式化数字;它不会正确处理分数分隔符和特定于语言环境的数字。考虑改用具有正确格式规范(%d或%f)的String#format。 不要传递字符串文字(例如“ Hello”)来显示文本。硬编码文本无法正确翻译为其他语言。考虑改用Android资源字符串。 不要通过串联文本块来构建消息。此类消息无法正确翻译。 我能为此做什么?任何人都可以帮助解释这是什么,我该怎么办?

8
在添加内容之前必须先调用requestFeature()
我正在尝试实现自定义标题栏: 这是我的助手类: import android.app.Activity; import android.view.Window; public class UIHelper { public static void setupTitleBar(Activity c) { final boolean customTitleSupported = c.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); c.setContentView(R.layout.main); if (customTitleSupported) { c.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.titlebar); } } } 这是我在onCreate()中称呼它的地方: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setupUI(); } private void setupUI(){ setContentView(R.layout.main); UIHelper.setupTitleBar(this); } 但是我得到了错误: requestFeature() must be …

15
禁用Android的Chrome下拉至刷新功能
我为公司创建了一个小型HTML5 Web应用程序。 此应用程序显示项目列表,一切正常。 该应用程序主要用于Android手机和Chrome浏览器。此外,该网站保存在主屏幕上,因此Android可以将整个内容作为应用程序进行管理(我猜是使用WebView)。 Chrome Beta(我也认为Android System WebView)已经引入了“下拉刷新”功能(例如,请参阅此链接)。 这是一个方便的功能,但是我想知道是否可以使用某些meta标记(或javascript东西)将其禁用,因为用户可以在浏览列表时轻松触发刷新,然后重新加载整个应用。 这也是应用程序不需要的功能。 我知道此功能仅在Chrome beta版中仍然可用,但是我有一种感觉,那就是该功能也将登陆稳定的应用程序。 谢谢! 编辑:我已经卸载了Chrome Beta,并且固定到主屏幕的链接现在随稳定的Chrome一起打开。因此,固定链接以Chrome开头,而不是以webview开头。 编辑:今天(2015-03-19)下拉菜单已刷新到稳定的Chrome。 编辑:从@Evyn答案我点击此链接并获得了有效的javascript / jquery代码。 显示代码段 var lastTouchY = 0; var preventPullToRefresh = false; $('body').on('touchstart', function (e) { if (e.originalEvent.touches.length != 1) { return; } lastTouchY = e.originalEvent.touches[0].clientY; preventPullToRefresh = window.pageYOffset == 0; }); $('body').on('touchmove', function …

18
java.lang.IllegalStateException:onSaveInstanceState之后无法执行此操作
我正在为我的应用程序使用支持库。在我的FragmentActivity中,我使用AsyncTask从互联网下载数据。在onPreExecute()方法中,我添加一个片段,在onPostExecute()方法中,我再次将其删除。当方向在这两者之间改变时,出现上述异常。请看一下详细信息: private class onFriendAddedAsyncTask extends AsyncTask<String, Void, String> { DummyFragment dummyFragment; FragmentManager fm; FragmentTransaction ft; @Override protected void onPreExecute() { Log.v("MyFragmentActivity", "onFriendAddedAsyncTask/onPreExecute"); dummyFragment = DummyFragment.newInstance(); fm = getSupportFragmentManager(); ft = fm.beginTransaction(); ft.add(dummyFragment, "dummy_fragment"); ft.commit(); } @Override protected void onPostExecute(String result) { Log.v("MyFragmentActivity", "onFriendAddedAsyncTask/onPostExecute"); ft = fm.beginTransaction(); ft.remove(dummyFragment); ft.commit(); } @Override …

11
ListView为空时显示空视图
由于某种原因,即使ListView不为空,空视图(在这种情况下为TextView)始终会出现。我认为ListView会自动检测何时显示空视图。 <RelativeLayout android:id="@+id/LinearLayoutAR" android:layout_height="fill_parent" android:layout_width="fill_parent"> <ListView android:id="@+id/ARListView" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView> <ProgressBar android:id="@+id/arProgressBar" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true"></ProgressBar> <!-- Here is the view to show if the list is emtpy --> <TextView android:id="@id/android:empty" android:layout_width="match_parent" android:layout_height="match_parent" android:text="No Results" /> </RelativeLayout> 如何正确连接空视图?
135 android  listview 

23
Java用非零退出值2结束-Android Gradle
我在执行我的Android应用程序时遇到此错误(我先清理了它,然后构建了它,但该错误仍然存​​在) 同步:确定 制作项目:确定 清洁:可以 运行:错误 错误:任务':app:dexDebug'的执行失败.com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:处理'command'C:\ Program Files \ Java \ jdk1.7.0 _25 \ bin \ java.exe''的退出值非零2 我的gradle文件: apply plugin: 'com.android.application' android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { applicationId "com.rzr.rzevallosr.miappdepruebas" minSdkVersion 19 targetSdkVersion 21 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } …

7
如何将变量从Activity传递到Fragment,然后传递回去?
我目前正在制作一个android应用,我想在活动和片段之间传递一个日期。我的活动有一个按钮,它将打开片段:DatePickerFragment。 在我的活动中,我显示一个日期,我想用该片段进行修改。所以我想将日期传递给日期选择器,然后将其发送回活动。 我尝试了很多解决方案,但是都没有用。简单的方法是传递一个参数,但这不能通过片段来完成。


10
如何在PreferenceScreen中添加按钮?
我刚接触Android开发,刚遇到偏好设置。我发现PreferenceScreen并想用它创建一个登录功能。我唯一的问题是我不知道如何在上添加“登录”按钮PreferenceScreen。 这是我的PreferenceScreen样子: <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> ... <PreferenceScreen android:title="@string/login" android:key="Login"> <EditTextPreference android:persistent="true" android:title="@string/username" android:key="Username"></EditTextPreference> <EditTextPreference android:title="@string/password" android:persistent="true" android:password="true" android:key="Password"></EditTextPreference> </PreferenceScreen> ... </PreferenceScreen> Button应该在两个EditTextPreferences的正下方。 有没有解决此问题的简单方法?我发现的一个解决方案由于我使用sub PreferenceScreens 而无法正常工作。 更新: 我发现我可以这样添加按钮: <PreferenceScreen android:title="@string/login" android:key="Login"> <EditTextPreference android:persistent="true" android:title="@string/username" android:key="Username"></EditTextPreference> <EditTextPreference android:title="@string/password" android:persistent="true" android:password="true" android:key="Password"></EditTextPreference> <Preference android:layout="@layout/loginButtons" android:key="loginButtons"></Preference> </PreferenceScreen> 布局文件(loginButtons.xml)如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:layout_width="fill_parent" …

7
如何使用Android的camera或camera2 API来支持旧版本和新版本的API,而无需弃用说明?
新的camera2 API使我感到困惑。我想开发一个使用设备摄像头的应用程序(适用于Android API 10-21)。如前所述这里,我应该使用“相机” API。 但是,当我尝试将“ Camera” API (android.hardware.Camera)添加到清单的用户功能时,它被标记为已弃用。另一方面,我无法将其更改为“ camera2” API (android.hardware.camera2),因为它仅与Android API 21+(Android 5-Lollipop)兼容-也会链接它,但我只能添加2个链接。 我不仅希望我的应用程序在旧版Android上运行,而且还希望在最新版本上运行。

9
如何更改每种Gradle构建类型的应用程序名称
我试图找出一种方法可以更改gradle中每种构建类型的应用程序的应用程序名称。 例如,我想要调试版本<APP_NAME>-debug和qa版本<APP-NAME>-QA。 我熟悉: debug { applicationIdSuffix '.debug' versionNameSuffix '-DEBUG' } 但是,在启动器中,我似乎找不到gradle命令来应用更改。

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.