Questions tagged «android»

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

13
ScrollView中的Recyclerview无法平滑滚动
对于我的应用我使用的是RecyclerView内部的ScrollView,其中RecyclerView有基于使用其内容的高度这个库。滚动正常,但在上滚动时效果不佳RecyclerView。当我滚动ScrollView自身时,它会平滑滚动。 我用来定义的代码RecyclerView: LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false); mFriendsListView.setLayoutManager(friendsLayoutManager); mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null)); 该RecyclerView在ScrollView: <android.support.v7.widget.RecyclerView android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:id="@+id/friendsList" android:layout_width="match_parent" android:layout_height="wrap_content" />

5
attrs.xml中用于自定义视图的同名属性
我正在写一些共享一些同名属性的自定义视图。在它们各自的<declare-styleable>部分中,attrs.xml我想对属性使用相同的名称: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="MyView1"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> <declare-styleable name="MyView2"> <attr name="myattr1" format="string" /> <attr name="myattr2" format="dimension" /> ... </declare-styleable> </resources> 我在说一个错误myattr1并且myattr2已经定义了。我发现我应该省略和中的format属性,但是如果这样做,我会在控制台中收到以下错误:myattr1myattr2MyView2 [2010-12-13 23:53:11 - MyProject] ERROR: In <declare-styleable> MyView2, unable to find attribute 有什么办法可以做到这一点,也许是某种命名空间(只是猜测)?

15
如何正确返回上级活动?
我的Android应用程序中有2个活动(A和B),并且使用了从活动A到活动B的意图。启用了parent_activity的使用: <activity android:name=".B" android:label="B" > <meta-data android:name="android.support.PARENT_ACTIVITY" android:value="com.example.app_name.A" /> </activity> 我还使用提供UP按钮的主题。 因此,在我调用活动BI之后,BI可以使用UP按钮返回活动A。问题是应用程序似乎再次调用了活动A 的onCreate() -函数,这不是我需要的行为。我需要活动A的外观与调用活动B之前的外观相同。 有没有办法做到这一点? 提前致谢 编辑: 我没有编写任何代码来从活动A开始活动B。我认为它是由Eclipse自动生成的。 B类看起来像: @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_b); getActionBar().setDisplayHomeAsUpEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.activity_b, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case …

19
Android推送通知:图标未显示在通知中,而是显示白色正方形
我的应用程序生成了一个通知,但未显示我为此通知设置的图标。相反,我得到一个白色正方形。 我尝试过调整图标的png大小(尺寸720x720、66x66、44x44、22x22)。奇怪的是,当使用较小的尺寸时,白色正方形较小。 我用谷歌搜索了这个问题,以及生成通知的正确方法,从我的阅读中我的代码应该是正确的。可悲的是事情没有达到应有的状态。 我的手机是带有Android 5.1.1的Nexus 5。模拟器,带Android 5.0.1的三星Galaxy s4和带Android 5.0.1的摩托罗拉Moto G(模拟器)也存在问题(我都借了,现在都没有) 通知代码如下,还有两个屏幕截图。如果您需要更多信息,请随时提出要求。 谢谢你们。 @SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) { NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class); resultIntent.putExtras(bundle); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK); Notification notification; Uri sound = Uri.parse("android.resource://" + …

20
INSTALL_FAILED_USER_RESTRICTED:使用Redmi 4设备的Android Studio
得到了这个怪异的错误 Installation failed with message Failed to finalize session : INSTALL_FAILED_USER_RESTRICTED: Install canceled by user. It is possible that this issue is resolved by uninstalling an existing version of the apk if it is present, and then re-installing. WARNING: Uninstalling will remove the application data! Do you want to uninstall …

13
如何在Android中制作倒数计时器?
我有两个XML的EditText。用户可以在一个EditText中输入一个数字,以分钟为单位,在另一个EditText中,输入一个数字,以秒为单位。单击完成按钮后,秒EditText应该开始倒计时并每秒更新其文本。 另外,如何保持更新直到零分钟零秒?
179 android  timer  countdown 

4
为什么构建类型与产品口味不同?
前言:这不是关于如何在Android应用程序中使用构建类型和产品风格的问题。我了解所涉及的基本概念。这个问题更多的是关于尝试了解在构建类型中应该指定哪个配置,在产品类型中应该指定哪个配置以及是否真的需要区分的问题。 本周,我一直在学习有关Android应用程序的gradle配置的更多信息。最初,我认为我对构建类型和产品风格有很好的了解,但是我对文档的了解越深,我就越发意识到两者之间的区别对我来说根本不清楚。 由于存在一个定义明确的层次结构(从某种意义上来说,在构建类型中指定的属性优先于在产品风味中指定的属性),我不明白为什么根本不需要区分构建类型和产品风味。将所有属性和方法合并到产品风味DSL对象中,然后将构建类型视为(默认)风味维,这会更好吗? 一些引起我困惑的具体例子: signingConfig可以在构建类型和产品风格中设置该属性...但是minifyEnabled(我假设,shrinkResources?)只能在构建类型中进行配置。 applicationId只能在产品口味中指定...并且applicationIdSuffix只能在构建类型中指定! 实际问题: 在上述示例的基础上:构建类型与产品风味的作用之间是否有明显的区别? 如果是这样,了解它的最佳方法是什么? 如果不是,是否计划最终将构建类型和产品类型合并到一个可配置的DSL对象中?

17
在React Native中更改Android的软件包名称
我曾经react-native init MyApp初始化一个新的React Native应用程序。这创建了一个带有软件包的Android项目com.myapp。 将此包名称更改为例如的最佳方法是com.mycompany.myapp什么? 我尝试更改它,AndroidManifest.xml但它创建了其他错误,因此我假设这不是方法。 任何想法?

11
Google Play服务GCM 9.2.0要求“更新”回9.0.0
所以今天早上我开始更新到我的项目库的最新版本。 我正在尝试将GCM更新到最新版本9.2.0,但出现此错误: 错误:任务':app:processDebugGoogleServices'的执行失败。请通过更新google-services插件的版本来解决版本冲突(有关最新版本的信息,请访问https://bintray.com/android/android-tools/com.google.gms.google-services/)或将com.google.android.gms的版本更新为9.0.0。 这就是我的代码: dependencies { classpath 'com.android.tools.build:gradle:2.1.2' classpath 'com.google.gms:google-services:3.0.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' } 然后: dependencies { ... compile "com.google.android.gms:play-services-gcm:9.2.0" ... } 是否有人遇到相同问题/已解决相同问题? 谢谢。 编辑 显然,您必须在app / build.gradle文件的底部应用GSM插件。否则,版本9.2.0将在您的项目中引起冲突。 作为参考,这是我的app / build.gradle文件的外观: apply plugin: "com.android.application" apply plugin: "com.neenbedankt.android-apt" android { ... } dependencies { ... // Google Cloud Messaging compile "com.google.android.gms:play-services-gcm:9.2.0" ... …

6
styles.xml中的自定义属性
我已经创建了一个自定义窗口小部件,并在layout.xml中声明了它。我还在attr.xml中添加了一些自定义属性。但是,当尝试在styles.xml中以样式声明这些属性时,这给了我No resource found that matches the given name: attr 'custom:attribute'. 我已经将xmlns:custom="http://schemas.android.com/apk/res/com.my.package"styles.xml中的所有标记(包括<?xml>,<resources>和)放入了所有标记中<style>,但是仍然出现相同的错误,即找不到我的自定义XML名称空间。 但是,我可以使用命名空间在layout.xml中为视图手动分配属性,因此命名空间没有任何问题。我的问题在于使styles.xml了解我的attr.xml。

22
如何调整文字字体大小以适合TextView
android中有什么方法可以调整textview中的textsize以适应其占用的空间? 例如,我使用a TableLayout并TextView在每行中添加几个。因为我不希望TextViews包装文本,所以我宁愿看到它减小了内容的字体大小。 有任何想法吗? 我已经尝试过了measureText,但是由于我不知道列的大小,因此使用起来似乎很麻烦。这是我想要将字体大小更改为适合的代码的代码 TableRow row = new TableRow(this); for (int i=0; i < ColumnNames.length; i++) { TextView textColumn = new TextView(this); textColumn.setText(ColumnNames[i]); textColumn.setPadding(0, 0, 1, 0); textColumn.setTextColor(getResources().getColor(R.drawable.text_default)); row.addView(textColumn, new TableRow.LayoutParams()); } table.addView(row, new TableLayout.LayoutParams());

4
Android .idea / misc.xml的languageLevel标签不断更改JDK
由于我不知道的原因,languageLevel密钥从JDK_1_8更改为JDK_1_7。 可能会发生什么? 这与从事该项目的其他开发人员的IDE有关吗?也许他们还有另一个Android Studio设置? 这是在我发现源代码管理下的文件已更改后弹出的内容: $ git diff diff --git a/.idea/misc.xml b/.idea/misc.xml index fbb6828..5d19981 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ <ConfirmationsSetting value="0" id="Add" /> <ConfirmationsSetting value="0" id="Remove" /> </component> - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" …



25
Android如何在可见软键盘时在全屏模式下调整布局
当软键盘处于活动状态时,我已经进行了很多研究来调整布局,并且我已经成功实现了它,但是当我android:theme="@android:style/Theme.NoTitleBar.Fullscreen"在清单文件中的活动标签中使用它时,问题就来了。 为此,我使用android:windowSoftInputMode="adjustPan|adjustResize|stateHidden"了其他选项,但没有运气。 之后,我以FullScreen编程方式实施并尝试使用各种布局,FullScreen但徒劳无功。 我引用了这些链接,并在此处查找了许多与此问题相关的帖子: http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html http://davidwparker.com/2011/08/30/android-how-to-float-a-row-above-keyboard/ 这是xml代码: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout android:id="@+id/masterContainerView" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android" android:background="#ffffff"> <ScrollView android:id="@+id/parentScrollView" android:layout_width="fill_parent" android:layout_height="wrap_content"> <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:id="@+id/setup_txt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Setup - Step 1 of 3" android:textColor="@color/top_header_txt_color" android:textSize="20dp" android:padding="8dp" android:gravity="center_horizontal" /> <TextView android:id="@+id/txt_header" android:layout_width="fill_parent" android:layout_height="40dp" android:text="AutoReply:" android:textColor="@color/top_header_txt_color" android:textSize="14dp" android:textStyle="bold" android:padding="10dp" android:layout_below="@+id/setup_txt" …

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.