如何在片段中获取上下文?
我需要用我的数据库其构造函数采用的背景下,但getApplicationContext()并FragmentClass.this没有工作,所以我能做些什么?
数据库构造函数
public Database(Context ctx)
{
    this.context = ctx;
    DBHelper = new DatabaseHelper(context);
}
Run Code Online (Sandbox Code Playgroud) 在Eclipse中,当您将鼠标悬停在某个方法上时,会出现一个窗口,其中包含该方法的作用,参数的含义以及返回的内容.有没有办法让Android Studio做同样的事情?
试图移动我的东西Toolbar而不是动作栏,但我不断收到错误说
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tyczj.weddingalbum/com.xxx.xxx.MainActivity}: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
            at android.app.ActivityThread.access$600(ActivityThread.java:141)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:137)
            at android.app.ActivityThread.main(ActivityThread.java:5039)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. …Run Code Online (Sandbox Code Playgroud) android android-actionbar material-design android-5.0-lollipop android-toolbar
我试图使用Notification.Builder.setLargeIcon(bitmap)带有位图图像.我有我想在可绘制文件夹中使用的图像,那么如何将其转换为位图?
我在一个活动我使用工具栏更改颜色Palette,但使用5.0的设备ActionBarActivity的status bar颜色是我的颜色colorPrimaryDark我的活动主题,所以我有2个非常不同的颜色和它看起来并不好.
我意识到在5.0你可以使用,Window.setStatusBarColor()但ActionBarActivity没有这个.
所以我的问题是在5.0中如何更改状态栏颜色ActionBarActivity?
在我的开发者控制台中,人们不断报告我无法在任何手机上重现的错误.一个人在尝试打开电池服务的设置屏幕时留下了一条消息说他得到了它.从错误中可以看出,它表示接收器未注册.
java.lang.RuntimeException: Unable to stop service .BatteryService@4616d688:  java.lang.IllegalArgumentException: Receiver not registered: com.app.notifyme.BatteryService$BatteryNotifyReceiver@4616d9d0
at android.app.ActivityThread.handleStopService(ActivityThread.java:3164)
at android.app.ActivityThread.access$3900(ActivityThread.java:129)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2173)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: Receiver not registered:com..BatteryService$BatteryNotifyReceiver@4616d9d0
at android.app.ActivityThread$PackageInfo.forgetReceiverDispatcher(ActivityThread.java:805)
at android.app.ContextImpl.unregisterReceiver(ContextImpl.java:859)
at android.content.ContextWrapper.unregisterReceiver(ContextWrapper.java:331)
at com.app.notifyme.BatteryService.onDestroy(BatteryService.java:128)
at android.app.ActivityThread.handleStopService(ActivityThread.java:3150)
Run Code Online (Sandbox Code Playgroud)
我注册的是我的onCreate
@Override
public void onCreate(){
    super.onCreate();
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    IntentFilter filter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    filter.addAction(Intent.ACTION_POWER_CONNECTED);
    filter.addAction(Intent.ACTION_POWER_DISCONNECTED);
    registerReceiver(batteryNotifyReceiver,filter);
    pref.registerOnSharedPreferenceChangeListener(this);
}
Run Code Online (Sandbox Code Playgroud)
取消注册onDestroy以及首选项侦听器
    @Override
public void onDestroy(){
    super.onDestroy();
    unregisterReceiver(batteryNotifyReceiver);
} …Run Code Online (Sandbox Code Playgroud) 我没有看到任何有关如何使用NotificationCompat与Android O的信息 Notification Channels
我确实看到一个新的构造函数,它接受一个channelId但是如何获取Compat通知并在NotificationChannel中使用它,因为createNotificationChannel它需要一个NotificationChannel对象
将新项目插入此类数据库时
Uri uri = getContentResolver().insert(Tournaments.CONTENT_URI, values); 
Run Code Online (Sandbox Code Playgroud)
有没有办法从返回的uri获取id,所以我不必运行查询来获取id,因为它已经在返回的uri中?
我Shared Element Transitions在活动之间工作.转换工作正常,但我想知道共享元素转换何时结束,以便我可以显示其他内容.
我尝试onSharedElementEnd在SharedElementCallback我转换到的活动中使用in ,但在转换开始之前调用它.
还有我可以听的另一个回调吗?
正如平板电脑版的gmail和google talk中所见,我试图在列表视图中显示当前选择.我知道这不是标准做法,应该在必要时予以避免.在我的程序中,列表视图总是在屏幕上,点击的项目显示右侧的新片段(类似于gmail和google talk).
为了避免用户猜测选择了哪个项目,我想显示当前的选择,我尝试创建一个选择器,但在点击它之后它会变回正常的背景.
我该怎么做到这一点?
这是我的选择器xml
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/list_item_bg2" android:state_pressed="false" android:state_selected="false"
    android:state_focused="false"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="true"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="false" android:state_focused="false"
    android:state_selected="true" android:state_checked="false"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="false" android:state_focused="true"
    android:state_selected="false"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="false" android:state_focused="false"
    android:state_selected="false" android:state_checked="true"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="true" android:state_focused="true"
    android:state_selected="true" android:state_checked="true"/>
<item android:drawable="@drawable/list_item_selected_bg2" android:state_pressed="true"/>
</selector> 
Run Code Online (Sandbox Code Playgroud)