- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
这是我的应用程序的简短草图
...
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.start);
... //at this place, getWindow().setBackgroundDrawableResource(int resid)
//would work perfectly
mainView();
}
void mainView() {
setContentView(R.layout.main);
...
if (...) {
getWindow().setBackgroundDrawableResource(R.drawable.anyDrawable);
}
...
}
但在 mainView() 中,该方法不会产生任何影响。并且没有异常被抛出。
main.xml 已经定义了背景图像,但 start.xml 没有定义。这会导致我的问题吗?
或者我可以用其他方式更改背景图片吗?
最佳答案
PS 你不能多次设置内容 View ,你应该做的是在布局中有一个 ID 像 main 这样的父 View ,然后使用
findViewById(R.id.main).setBackgroundDrawableResource(R.drawable.anyDrawable);
并且在xml布局中你需要设置你想设置的 View 的id(这应该是最顶层的 View )
<?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"
android:padding="16dip"
android:id="@+id/main"></LinearLayout>
将 id 添加到 View 后,您需要保存布局并构建项目
如果您想发布您的 xml 代码以及您的布局名称,我可以为您编写更多内容
关于android - 方法 getWindow().setBackgroundDrawableResource(int resid) 在 onCreate() 之外不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10933179/
它们有什么区别?据我所知,他们都做同样的事情。 最佳答案 如果你去资源,你会发现PhoneWindow.class实现了 Window.setBackgroundDrawable 方法: @Overr
编辑:在形成这个问题时,我没有注意到目标窗口是模态窗口,所以我尝试的方法是错误的。我应该一直使用 GetModal,而不是 GetWindow。留在这里作为 future 旅行者的潜在引用 我正在尝试
JSObject.equals 的文档说: Determines if two JSObject objects refer to the same instance. 相反,以下表达式的计算结果为
这可能是一个愚蠢的问题,但我有以下情况:我想在每次打开应用程序时设置窗口布局,例如更改状态栏颜色。所以我创建了我的应用程序文件,因为我听说如果您在应用程序文件中而不是在 MainActivity 中检
我已经为 ics 创建了一个锁屏,它将取代默认的锁屏。在我的代码中,我想使用 getWindow() 方法来设置 "android:hardwareAccelerated" true 以提高效率。 我
我正在尝试一些 Java/JavaScript 编码,但似乎遇到了困难。我试图将参数从 Java 传递到 JavaScript,但无论我做什么“JSObject jso = JSObject.getW
来自How to reference primaryStage我了解到,我可以使用 control.getScene.getWindow() 获取特定控件的 Stage,但这会返回一个 Window
我明白 TypeError: this.getWindow(...).$ is undefined 当我使用CKEDITOR.instances['pageContent'].getData();使用
下面一行代码中的getWindow()方法 this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_
在source for jQuery's offset() ,为什么不能直接用window呢? 最佳答案 以防元素实际上不在 window 上。例如,它可能位于 iFrame 或弹出窗口中。 关于ja
我看过以下帖子 How to keep background image size when software keyboard show Software keyboard resizes back
在我的 Android 项目中,我希望只有一个 fragment 的 softInputMode 为 adjustPan。 将以下行添加到我的 list (在 Activity 内)按预期工作: an
我正在尝试绘制一些颜色介绍对话框,我有几个按钮(用于选择颜色)和一个 CStatic 控制我将使用哪个窗口来绘制所选颜色它。但是,当我调用 m_myStatic.GetWindow( NULL ) 时
public class AircraftFragmentTab extends Fragment{ private String ac; public Aircr
我无法解决 getWindow();出于某种原因的方法... import java.applet.Applet; import netscape.javascript.JSObject; publi
我有一些Android应用程序的类文件,我有代码 protected void onCreate(Bundle bundle) { super.onCreate(bundle);
我正在尝试获取 Android 中的屏幕亮度。 场景是这样的:A 类调用 B 类的函数: A类: if(condition is true){ ClassB.function(); } B类: f
我按顺序调用了以下两个方法(按顺序使用适当的类级别字段) public const string ProcessName = "This is" public const string WindowT
我需要检查是否已在 ActionBarCompat 实例上设置叠加功能。 getWindow().hasFeature() 方法仅适用于 API 11 及更高版本。 如何检查 API = 11) {
我创建了一个完全适合设备显示的背景图像,没有状态栏和操作栏。这意味着我的设备的整个高度是 1280 像素。没有状态栏和操作栏它是 1038 像素。我的背景图片正好是 1038 像素高。当我将图像设置为
我是一名优秀的程序员,十分优秀!