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

android – 相对布局宽度/高度不能以编程方式工作?【代码】

我想以编程方式进行相对布局并设置android:layout_widht = 60 android:layout_height = 60.当我以编程方式执行时,它是否填满所有屏幕?我怎样才能做到这一点? 我的代码:`RelativeLayout relativeLayout=new RelativeLayout(getContext());RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);rel_btn.height = 60;rel_btn.width = 60;relativeLayo...

android – 在哪里可以找到使用Cocos2D-x开始编程的好教程?

我在linux android上使用cocos2D开始编程时遇到了一些问题. 我使用稳定版本0.12.0(2012-03-05) >我正确编译了create-linux-eclipse-project.sh>它在同一路径上创建一个TestCocos2D项目>我将android项目导入Eclipse>我运行项目,我得到了你好的世界. 但我不知道从哪里开始编程场景,导演以及如何使用它. 我试过This tutorial但是太老了.我不能使用official教程因为我不知道在哪里使用代码. 一些建议/教程请开始吗? 解: 如果您在这里...

以编程方式更改android:digits【代码】

我在布局xml中有这个android:digits="0123456789." android:inputType="phone" />我想要的是能够以编程方式更改它并能够来回更改它.inputType部分很好用manual_ip.setInputType(InputType.TYPE_CLASS_TEXT);要么manual_ip.setInputType(InputType.TYPE_CLASS_PHONE);但我对数字部分一无所知..我需要将字符限制为“0123456789”.或根据复选框状态允许所有内容.解决方法:添加manual_ip.setKeyListener(DigitsKeyListener.getInstance...

是否能够在android上以编程方式触发`MotionEvent.ACTION_DOWN`事件?【代码】

这是一些简单的android代码:@Override public boolean onTouch(View v, MotionEvent event) {int action = event.getAction();switch (action & MotionEvent.ACTION_MASK) {case MotionEvent.ACTION_DOWN:// do somethingbreak;case MotionEvent.ACTION_MOVE:// do something// how to trigger a ACTION_DOWN event here?break; }我想在处理ACTION_MOVE时触发ACTION_DOWN事件.可能吗?解决方法:你可以这样试试.@Override public b...

android – 以编程方式在TextView中居中文本【代码】

我以编程方式创建了一个TextView,文本和背景可绘制.我想将文本居中在TextView中,但文本居于顶部. 这是我在TextView中居中文本的代码:protected class TileView extends TextView{private int tileType;private int col;private int row;protected TileView(Context context, int row, int col, int tileType) {super(context);this.col = col;this.row = row;this.tileType = tileType;String result = Integer.toString(RandomNu...

是否有可能以编程方式关闭android中的浏览器选项卡?

我有一个应用程序,它从本地服务器播放音乐并在Web浏览器中打开音乐播放器但是当用户返回到Home活动并启动另一个在浏览器上播放视频的活动时,视频将在另一个选项卡中打开.浏览器,而音乐标签不会关闭. 当另一个标签打开时,我可以关闭已打开的浏览器标签吗?如果不.请提出一些解决方法.解决方法:您无法控制其他应用程序的生命周期.因此您无法关闭浏览器中运行的选项卡. 另一方面,您可以使用WebView来打开音频/视频然后你可以完全控制它...

android – 以编程方式添加具有纯色和笔触的渐变【代码】

目前我正在使用此代码添加颜色:ShapeDrawable drawable = new ShapeDrawable(new OvalShape()); drawable.getPaint().setColor(color);现在我需要将一些渐变颜色与笔划一起应用(如不同颜色的边框).我将此设置为按钮的背景. 这是我所期待的,我需要以编程方式进行.解决方法:像这样在你的drawable中添加一个RadialGradient:Shader shader = new RadialGradient(x, y, radius, color0, color1, Shader.TileMode.REPEAT); drawable.ge...

android – 如何以编程方式查看用户是否在从付费更改为免费时为我的应用付费

我有两个版本的应用程序.免费和专业.我将删除免费版本,并将专业版的状态从付费更改为免费,并在应用结算中使用以解锁高级功能,而不是拥有两个不同的应用.已付款的用户应该从启用所有功能开始. 有没有办法检查用户是否在将应用程序更改为免费后购买了应用程序? 从我所读到的,LVL不能这样做. 是否可以使用IAB v3?解决方法:StackOverflow上有几个关于此主题的帖子.简短的回答是,没有万无一失的方法可以做到这一点. 一些可能性: >专门...

以编程方式设置android textView drawableEnd

如何从java代码中设置TextView的android:drawableEnd?setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int)只能用于left,right,top和bottom.如何设置drawableEnd?解决方法:有一个类似的方法叫做setCompoundDrawablesRelativeWithIntrinsicBounds(int,int,int,int),其中参数引用start,top,end,bottom 您需要具有最低级别为17或更高的API.

Locale未在Android 5.0 Lollipop中以编程方式设置【代码】

我的应用程序根据应用程序中的选定语言设置区域设置到Kitkat我的代码工作正常.更新到Lollipop后,未设置区域设置.在这里,我粘贴我的代码来设置区域设置..Locale locale = new Locale("de_DE"); Locale.setDefault(locale); Configuration config = new Configuration(); config.locale = locale; getBaseContext().getResources().updateConfiguration(config, null);解决方法:您必须更改区域设置初始化的方式.由此:Locale locale ...

如何在Android中以编程方式隐藏布局/视图【代码】

我刚刚开始学习Android.我对XML中的布局几乎没有什么困惑 >我在布局中定义的所有视图是否基本上都是夸大的,或者它们是可选的?假设我在视图组中有两个不同的视图,但我想有条件地仅使用第一个或仅第二个.可能吗?>动态创建的视图如何处理layout.XML文件?>如果我希望收到的消息以红色显示并以黑色发送消息,我该怎么办?解决方法:您可以在XML布局文件中包含不可见的视图,直到以编程方式显示它们.只需在XML文件中使用“android:visib...

android – 在导航视图中以编程方式将项目添加到菜单组【代码】

我正在尝试将菜单项添加到菜单组中,但我发现无法做到这一点.我正在使用导航视图并添加下面提到的菜单:<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:id="@+id/nav_lang_currency"android:title="" /><itemandroid:id="@+id/nav_home"android:title="" /><group android:id="@+id/nav_refer" /><itemandroid:id="@+id/nav_setting"android:title="" /><...

android – 以编程方式确定设备是手机还是平板电脑【代码】

我有一个包含2个布局的活动的应用程序: > layout / activity_main.xml – “手机模式”,里面有一个视图(列表)> layout-w900dp / activity_main.xml – “平板电脑模式”,包含2个视图(列表和详细信息) 通常,我会检查功能的详细信息:if (findViewById(R.id.application_detail_container) != null) {// The detail container view will be present only in the// large-screen layouts (res/values-w900dp).// If this view is p...

android – Textview选框以编程方式【代码】

尝试从数组中填充textview.我通过下面的代码设法通过XML获得了预期的效果<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TextViewandroid:id="@+id/marque_scrolling_text"android:layout_width="match_parent"android:layout_height="wrap_content"...

Android – 如何以编程方式更改ImageButton的宽度?【代码】

我有一个ImageButton.代码是 – ImageButton shareButton = new ImageButton(this); shareButton.setBackgroundResource(android.R.drawable.ic_menu_share);RelativeLayout.LayoutParams shareParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); shareParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, navigationLogo.getId());shareButton.setLayoutParams(shareParams);我需...