Questions tagged «android»

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

10
如何在Android中使用TextWatcher类?
谁能告诉我如何掩盖子中EditText或如何改变EditText 串输入密码类型或更换另一个字符这样123xxxxxxxxx3455 String contents = et1.getText().toString(); et1.setText(contents.replace.substring(0, contents.length()-2),"*"); 请告诉我如何TextWatcher在Android中使用该方法。

9
如何将按钮变灰?
我定义了一个按钮,如下所示。当我想禁用它时,我使用my_btn.setEnabled(false),但我也想将其显示为灰色。我怎样才能做到这一点? 谢谢 <Button android:id="@+id/buy_btn" style="@style/srp_button" /> 样式/ srp_button <style name="srp_button" parent="@android:style/Widget.Button"> <item name="android:background">@drawable/btn_default</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:textColor">#ffffff</item> <item name="android:textSize">14sp</item> <item name="android:typeface">serif</item> <item name="android:paddingLeft">30dp</item> <item name="android:paddingRight">30dp</item> <item name="android:paddingTop">5dp</item> <item name="android:paddingBottom">5dp</item> </style> drawable / btn_default.xml <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="@color/pink" /> <corners android:radius="6dp" /> </shape>
103 android  button 

10
Intellij IDEA崩溃了,现在抛出一个错误
我在Intellij IDEA中工作,但是计算机死机,因此我关闭了计算机。(长按电源按钮)当我打开计算机并启动IntelliJ IDEA时,出现以下错误: Cannot load settings from file 'C:\Users\user\.IdeaIC13\config\options\code.style.schemes.xml': java.lang.AssertionError: Unexpected content storage modification File content will be recreated 我关闭IDEA并重新开始,现在没有上一个错误,但是当我打开项目时出现以下错误: Error:Internal error: (org.jdom.input.JDOMParseException) Error on line 1: Content is not allowed in prolog. org.jdom.input.JDOMParseException: Error on line 1: Content is not allowed in prolog. at org.jdom.input.SAXBuilder.build(SAXBuilder.java:533) at org.jdom.input.SAXBuilder.build(SAXBuilder.java:946) at com.intellij.openapi.util.JDOMUtil.loadDocument(JDOMUtil.java:364) …

6
更改导航抽屉中选中的菜单项的颜色
我正在使用新的Android Design支持库在我的应用程序中实现导航抽屉。 我不知道如何更改所选项目的颜色! 这是菜单的xml: <menu xmlns:android="http://schemas.android.com/apk/res/android"> <group android:checkableBehavior="single"> <item android:id="@+id/navigation_item_1" android:icon="@drawable/ic_1" android:title="@string/navigation_item_1"/> <item android:id="@+id/navigation_item_2" android:icon="@drawable/ic_2" android:title="@string/navigation_item_2"/> </group> 这是放置在内的navigationview xml android.support.v4.widget.DrawerLayout: <android.support.design.widget.NavigationView android:id="@+id/activity_main_navigationview" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/drawer_header" app:itemIconTint="@color/black" app:itemTextColor="@color/primary_text" app:menu="@menu/menu_drawer"> <TextView android:id="@+id/main_activity_version" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:layout_marginBottom="@dimen/activity_vertical_margin" android:layout_marginLeft="@dimen/activity_horizontal_margin" android:textColor="@color/primary_text" /> </android.support.design.widget.NavigationView> 谢谢您的帮助 ! [编辑]我已经研究过这样的解决方案:更改android菜单的背景颜色。 这似乎是一个hack,我认为使用新的设计支持库会引入更干净的东西吗?


24
如何在Android中隐藏状态栏
我提到了这个链接。在这种情况下,如果用户单击EditText(例如,To To),则会弹出键盘,同时用户可以滚动查看所有剩余的视图(例如:compose,subject,send按钮)。该屏幕。同样,在我的应用程序中,我有一个活动,就是我有一些小部件或视图。假设如果用户单击“我的活动”中的Edittext,则弹出键盘,并且我可以滚动查看其余视图。但是,如果我android:theme="@android:style/Theme.NoTitleBar.Fullscreen"在清单中指定此属性,则无法滚动以查看其余视图,但是如果Give属性android:theme="@android:style/Theme.NoTitleBar"像清单中这样,我可以滚动查看剩余的视图,但是该屏幕上有状态栏,这里我要全屏显示,即使弹出键盘,也可以滚动查看剩余的视图..?为此我需要做哪些更改?

9
Android-Snackbar vs Toast-用法和区别
到目前为止,我们仅在应用程序中使用Toasts,并且由于我们计划采用Support Design Library中的一些新功能,我想知道Snackbar vs. Toast的推荐用法是什么。 我一直在阅读Google的快餐栏文档。 小吃栏在移动设备屏幕底部和桌面左下方的小弹出窗口中提供有关操作的轻量级反馈。它们首先位于屏幕上的所有元素,包括FAB。 和烤面包。 Android还提供了一个胶囊状的吐司,主要用于系统消息传递。吐司类似于小吃店,但不包含动作,也不能在屏幕外滑动。 我知道他们在做什么,但是我什么时候使用它有点困惑。这是否意味着: 如果不需要用户交互,我会敬酒吗? “系统消息传递”是什么意思?当我的应用程序与Android系统之间发生重要事件时,这是否适用于显示信息? 我喜欢的是屏幕外滑动功能-这是否就是开始用小吃店代替吐司的原因?(尽管这是一个基于意见的问题)

3
Timertask或Handler
假设我想每隔10秒执行一次操作,而不必更新视图。 问题是:将timer与timertask一起使用会更好(我的意思是更有效): final Handler handler = new Handler(); TimerTask timertask = new TimerTask() { @Override public void run() { handler.post(new Runnable() { public void run() { <some task> } }); } }; timer = new Timer(); timer.schedule(timertask, 0, 15000); } 或只是带有延迟的处理程序 final Handler handler = new Handler(); final Runnable r …


6
我有一个错误:setOnItemClickListener无法与微调器一起使用,这是什么问题?
好的,这是下面的代码,我在下面粘贴了错误消息:我试图setOnItemClickListener在微调器上使用,是否可以使用? @Override public void onItemClick(AdapterView<?> arg0, View v, int index, long arg3) { if (quantity[index]=="Meter" ){ s1="Meter"; Toast.makeText(v.getContext(), "convert from meter",Toast.LENGTH_SHORT).show(); } } }); convertto.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg, View v1, int index1, long arg4) { if ((quantity[index1]=="Meter") && (s1.equalsIgnoreCase("Meter"))) { Toast.makeText(v1.getContext(), " to meter",Toast.LENGTH_SHORT).show(); var2=var1; lresult.setText("" …


6
Android WebView地理位置
我必须在中检索用户的位置WebView。我使用以下Javascript执行此操作: function getLocation() { navigator.geolocation.getCurrentPosition(displayLocation, handleError); } 但是权限请求弹出窗口永远不会打开。 我已经设置了以下设置: ws.setJavaScriptEnabled(true); ws.setGeolocationEnabled(true); ws.setJavaScriptCanOpenWindowsAutomatically(true); 从中访问用户位置的正确方法是WebView什么?

17
如何在Android中显示多个通知
我只收到一个通知,如果有另一个通知,它将代替前一个,这是我的代码 private static void generateNotification(Context context, String message, String key) { int icon = R.drawable.ic_launcher; long when = System.currentTimeMillis(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(icon, message, when); String title = context.getString(R.string.app_name); Intent notificationIntent = new Intent(context, FragmentOpenActivity.class); notificationIntent.putExtra(key, key); // set intent so it does …

8
使用attr / selectableItemBackground作为背景时,如何修改波纹颜色?
我已经看到了一些SO问题,他们提供了一些可能的方法来实现我想要的。例如: 用 colorControlHighlight在styles.xml中属性。 这是我的styles-v21.xml: <style name="SelectableItemBackground"> <item name="android:colorControlHighlight">#5677FC</item> <item name="android:background">?attr/selectableItemBackground</item> </style> 而我的小部件: <TextView android:id="@+id/tv_take_photo_as_bt" android:layout_width="280dp" android:layout_height="48dp" android:text="@string/act_take_photo" style="@style/SelectableItemBackground"/> 而且它不起作用。我还尝试添加parent="Theme.AppCompat到“ SelectableItemBackground”样式,或者更改为colorControlHighlight(no android: prefix)",或更改为?android:attr/selectableItemBackground,都没有用。 backgroundTint在布局中使用属性。 所以我加android:backgroundTint="#5677FC"了TextView。仍然没用。然后,我尝试将其更改android:backgroundTintMode为src_in和src_atop,但它们从未改变。 因此,当?attr/selectableItemBackground用作背景时,如何更改波纹颜色。我只关注棒棒糖及以上。先感谢您!

1
以样式使用App名称空间
我将举一个例子来说明更大的意义。 想象一下,我的应用程序有许多FloatingActionButtons。因此,我想创建一种样式并重用它。因此,我执行以下操作: <style name="FabStyle” parent ="Widget.Design.FloatingActionButton"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_margin">16dp</item> <item name="app:backgroundTint">@color/accent</item> <item name="app:layout_anchorGravity">end|bottom</item> </style> 我遇到的问题是代码无法编译,因为它在抱怨 Error:(40, 5) No resource found that matches the given name: attr 'app:backgroundTint'. 我尝试通过resources标签将名称空间引入,但这不起作用 <resources xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/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.