我想在java中设置我的导航抽屉的背景颜色,但似乎setBackgroundColor和所有类似的方法都没有效果.只有XML行android:background="@color/mycolor"正在运行.如果删除xml行并尝试其中一种方法,则抽屉保持透明.
有任何想法吗?
我试图让LinearLayouts我的一些,onCreateView但我的应用程序崩溃与以下消息:
23430-23430/? W/System.err? java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
Run Code Online (Sandbox Code Playgroud)
这是代码:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
new Body().execute();
card01 = (LinearLayout) getView().findViewById(R.id.card01);
card02 = (LinearLayout) getView().findViewById(R.id.card02);
card03 = (LinearLayout) getView().findViewById(R.id.card03);
card04 = (LinearLayout) getView().findViewById(R.id.card04);
card05 = (LinearLayout) getView().findViewById(R.id.card05);
card06 = (LinearLayout) getView().findViewById(R.id.card06);
card01.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getActivity(), "Card Clicked", Toast.LENGTH_SHORT).show();
}
});
return rootView; …Run Code Online (Sandbox Code Playgroud) java android nullpointerexception android-fragments android-activity
我尝试使用BackupAgent备份我的默认值sharedpreferences.这就是我的意思MyBackupAgent
public class MyBackupAgent extends BackupAgentHelper {
// The name of the SharedPreferences file
private final String PREFS = "com.mikebdev.refuelpro_preferences";
// A key to uniquely identify the set of backup data
private static final String PREFS_BACKUP_KEY = "prefs";
@Override
public void onCreate() {
SharedPreferencesBackupHelper sharedPref = new SharedPreferencesBackupHelper(this, PREFS);
addHelper(PREFS_BACKUP_KEY, sharedPref);
}
}
Run Code Online (Sandbox Code Playgroud)
从ADB强制备份和还原时,这是我在控制台中获得的:
shell@flo:/ $ bmgr backup com.mikebdev.refuelpro
bmgr backup com.mikebdev.refuelpro
shell@flo:/ $ bmgr backup run
bmgr backup run
shell@flo:/ $ bmgr restore com.mikebdev.refuelpro
bmgr restore …Run Code Online (Sandbox Code Playgroud) 我在Android Studio中理解Build Flavors时遇到了麻烦.我正在努力实现一个简单的事情:用一个小代码更改来建立2个签名的APK."亲"APK只是有一个不同drawer.xml的res/layout/.我已经阅读了文档中的一些内容和StackOverflow中的一些内容,但我没有看到我的build.gradle更改发生任何变化.
我目前的build.gradle档案:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.4.+'
}
}
apply plugin: 'android'
dependencies {
compile files('libs/android-support-v4.jar')
compile files('libs/GoogleAdMobAdsSdk-6.4.1.jar')
}
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 14
targetSdkVersion 17
}
productFlavors {
lite {
packageName = 'com.mikebdev.refuel'
}
pro {
packageName = 'com.mikebdev.refuelpro'
}
}
sourceSets{
android.sourceSets.pro {
res.srcDirs = ['src/main/res_pro']
}
}
}
Run Code Online (Sandbox Code Playgroud)
我创建了一个新文件夹:
/src/main/res_pro/layout/drawer.xml
Run Code Online (Sandbox Code Playgroud)
我在这做错了什么?
编辑
我更新了上面的build.gradle文件.
由于其他一些不稳定因素重置我的整个Android Studio后,我现在可以在左下角选择我的构建变体(lite-debug,lite-release,pro-debug,pro-release)为什么甚至那些调试和发布变体?
这似乎现在应该工作.
我在下面添加了一个答案
我正在努力计算服务器列表的百分比。
我所拥有的是:
icinga2.$server.services.Memory_Load.memory-windows.perfdata.memory.value
Run Code Online (Sandbox Code Playgroud)
和
icinga2.$server.services.Memory_Load.memory-windows.perfdata.memory.max
Run Code Online (Sandbox Code Playgroud)
我不知道如何计算这些值的百分比。
有人可以帮我吗?
我试图愚弄reduceSeries,mapSeries但asPercent总是从中得到一个查询错误。
我尝试过的例子:
reduceSeries(mapSeries(icinga2.$server.services.Memory_Load.memory-windows.perfdata.memory.*,1),"asPercent",3,"value","max")
Run Code Online (Sandbox Code Playgroud)
提前致谢