【安卓编程开发培训!请谈下Android消息机制,终局之战】教程文章相关的互联网学习教程文章

android – 以编程方式构建LinearLayout【代码】

我试图让我的布局看起来像这样: 我的包含此代码的类扩展了Linelayout本身,并使用addView添加了不同的元素setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));LinearLayout line = new LinearLayout(context);line.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));viewVerLabels = new VerLabelsView(context);// add y axis linearlayout & grap...

android – 如何在Phonegap 3.4.0上以编程方式退出应用程序?【代码】

我正在使用JQuery Mobile和Phonegap 3.4.0(Apache cordova)开发一个Android应用程序.我尝试以编程方式关闭应用程序,所以我尝试:navigator.app.exitApp();和navigator.device.exitApp();这是ondeviceready文档监听器:document.addEventListener("deviceready", onDeviceReady(), true); function onDeviceReady() {var today = new Date();var dd = today.getDate();if(dd==15) {alert("Your application has been expired");navi...

Android如何获取以编程方式使用应用程序应用程序的联系人列表【代码】

我在这个应用程序中使用小型Android应用程序我尝试获取联系人使用什么应用程序应用程序,并在联系人更新他/她的个人资料图片和状态时,从我的应用程序提醒我选择的什么应用程序联系人.解决方法:您可以查询内容光标以查看联系人具有的属性.Cursor c1 = appActivity.getContentResolver().query(ContactsContract.Data.CONTENT_URI,null,null,null, null); c1.moveToFirst(); DatabaseUtils.dumpCursor(c1); c1.close();或者特别是如果...

在Android上的Crosswalk WebView中以编程方式设置cookie【代码】

我需要在Android上使用Crosswalk(在Cordova项目中)使用一些我通过Apache HttpClient收集的cookie.但是我不知道如何实现这一目标.我试过试验XWalkCookieManager,但我想我做的一切XWalkCookieManager被忽略.我在哪里初始化cookie经理?这甚至支持了吗?//cookieStore contains the cookies I got via a request from the Apache // HttpClient.List<Cookie> cookies = cookieStore.getCookies();for (int i = 0; i < cookies.size();...

Android RecyclerView滚动到以编程方式无法正常工作【代码】

我正在尝试以编程方式滚动到我的RecyclerView中的一个位置,这是我尝试过的,直到现在我的情况没有任何作用:musicList.getLayoutManager().smoothScrollToPosition(musicList, null, position);musicList.scrollToPosition(position);mLayoutManager.scrollToPosition(position);musicList.getLayoutManager().scrollToPosition(position);我错过了什么吗? 我有一个LinearLayoutManager mLayoutManager;定义并将其设置为RecyclerVi...

android – 以编程方式点击或触摸recyclerview中的项目【代码】

如何强制点击或触摸Recyclerview上的项目? 我发现人们在谈论使用命令recyclerView.findViewHolderForAdapterPosition(0).itemView.performClick()但recyclelerView.findViewHolderForAdapterPosition(0)总是返回null! 我最初想要点击/触摸第一个recyclerview项目.解决方法:new Handler().postDelayed(new Runnable() {@Overridepublic void run() {recyclerView.findViewHolderForAdapterPosition(position).itemView.performCli...

当app运行时,如何在android中以编程方式关闭通知?【代码】

我正在尝试开发一个Android应用程序,我正在实现聊天功能.但是当我收到消息时它发出通知声音.当用户以编程方式使用应用程序时,如何停止通知?private void ChatNotifications(String uid, String fuid, String message) {NotificationCompat.BigTextStyle notiStyle = new NotificationCompat.BigTextStyle();notiStyle.setBigContentTitle("message");// notiStyle.setSummaryText(quote);notiStyle.bigText(message);Intent resul...

android – 以编程方式创建MapView并添加标记结果片段中的空指针异常【代码】

我正在尝试以编程方式创建MapView并添加MarkerPosition,如下所示:MapView mapView = new MapView(getActivity()); ((ViewGroup) rootView).addView(mapView);GoogleMap googleMap = mapView.getMap(); googleMap.addMarker(new MarkerOptions().position(new LatLng(Double.parseDouble(mEvent.getEventInfo().mEventData.mLat),Double.parseDouble(mEvent.getEventInfo().mEventData.mLng))).title("Marker"));清单文件:<uses-p...

java – 如何以编程方式制作可绘制的形状(Android)【代码】

我正在制作一个自定义TextView(Java类),我很难“翻译”该行(在“原始TextView”xml上)android:background="@drawable/myDrawableShape"到一个java void来改变“myDrawableShape”的颜色 myDrawableShape.xml<shape xmlns:android="http://schemas.android.com/apk/res/android" > <solid android:color="#ffafafaf" /> <corners android:radius="15dp" />我将从String中获取颜色,以编程方式更改颜色的void(例如)void colorSet(Stri...

以编程方式更改android按钮可绘制图标颜色【代码】

我想以编程方式从我的按钮更改我的图标颜色… 在我的xml上,我有:android:drawableTint="@color/colorPrimary"android:drawableTop="@drawable/ic_car_black_24dp"设置图标并设置图标颜色…但我想从我的java端更改图标颜色… 有人能帮我吗?<android.support.v7.widget.AppCompatButtonandroid:id="@+id/bt_search_vehicle_car"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_margin="@d...

Android进度微调器,能够显示但不能以编程方式隐藏【代码】

我正在尝试在我的testLayout.xml文件中指定一个进度微调器,然后以编程方式显示和隐藏它,就像我在下面的活动代码中所做的那样.然而,发生的事情是进度轮会显示,但即??使我有setProgressBarVisibility(false)它也永远不会消失;在末尾.有任何想法吗?谢谢你的意见 布局/ testLayout.xml <Button android:layout_width="fill_parent"android:layout_height="wrap_content" android:id="@+id/ButtonNew"android:text="New" android:l...

Android:如何以编程方式取消对SearchView的聚焦【代码】

我的布局中有一个SearchView(不在操作栏中),我无法使用常用方法关闭键盘:public static void hideKeyboard(Activity activity) {InputMethodManager imm = (InputMethodManager)activity.getSystemService(Context.INPUT_METHOD_SERVICE);if (imm != null && activity != null) {View currentFocus = activity.getCurrentFocus();if (currentFocus != null) {imm.hideSoftInputFromWindow(currentFocus.getWindowToken(), 0);}} }...

android – 以编程方式更改主启动器活动

我的应用程序用作启动器. 10分钟后,另一项活动自动开始.当此活动开始时,如果用户按下主页按钮,则返回主活动.但是,我想将启动器活动更改为第二个.即使按下主页按钮,也必须禁止返回主要活动.解决方法:我建议您创建一个没有UI的空白活动,而不是使用意图过滤器,并将其注册为启动器.此活动的唯一作用是选择您想要显示的正确实际活动,将其作为新任务启动,然后静默退出.

android – 非程序员编程指南

好的,所以我是一个非常低级的程序员,很高兴承认.鉴于基本语法,我可以编写简单的程序,如VB和python等.我想为android编写简单的程序,例如一个处理英尺和英寸的计算器,以及一个只搜索产品数据库并告诉我细节的程序.是否有一个简单的解决方案,我可以拖放一些按钮和文本框并执行代码或者我是否必须学习整个gui绘图代码并从头开始?如果我必须从头开始是否有一本书不假设我知道任何高级编码技术或者我是否必须学习整个语言然后学习SDK?我...

android – 以编程方式更改R.string的值?【代码】

我正在寻找一种动态更改字符串资源值的方法.我试图使用反射,但它声称“字段的值无效”. 我在布局中使用字符串作为值,但需要将它们换成不同的语言. 请参阅下面的附件代码.public class Lang{public static void langInit(){java.lang.reflect.Field[] langStringFields = R.string.class.getFields();Log.d(Global.TAG,"--> Lang Listing: " + langStringFields.length);Log.d(Global.TAG,"--> Pref for language:");String prefInL...