我想在Android Fragments中有一个选项菜单.ActionBar
选项菜单未显示在我的片段中.
这里是我的代码,我有两个onCreateOptionsMenu()
和onOptionSelected()
功能.我的代码没有显示任何错误.但是没有显示选项菜单.
package org.reachout;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import org.general.R;
public class ViewMessageFragment extends Fragment {
/* (non-Javadoc)
* @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
*/
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (container == null) {
// We have different layouts, and in one of them this
// fragment's containing frame doesn't exist. The fragment
// may still be created …
Run Code Online (Sandbox Code Playgroud) android android-fragments android-optionsmenu android-actionbar
就像iPhone有一个UIImagePickerController让用户访问存储在设备上的图片一样,Android SDK中是否有类似的控件?
谢谢.
我使用短信管理器发送短信.对于单一SIM卡,它可以完美地发送短信.但在双卡双待短信不会发送.是否可以从双卡发送短信,如果可能的话,我该如何选择哪个SIM卡发送短信.任何人都知道帮我解决这个问题.
单SIM卡工作代码
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(ph_number, null, body, null,null);
Run Code Online (Sandbox Code Playgroud) 我有两个环境,我的项目一个Prod另一个是Staging.因此,每当我必须构建任何环境时,我都必须更改多个键,例如地图键,标签名称和清单中的其他内容.所以我搜索并找出一些解决方案,而manifestPlaceholders就是其中之一.
现在我想做的是在manifestPlaceholders中分配多个值.那么我可以在其中放置多个值,是的,然后如何在其中放置多个值.这是manifestPlaceholders的代码
buildTypes {
debug {
manifestPlaceholders = [ google_map_key:"your_dev_key"]
}
release {
manifestPlaceholders = [ google_map_key:"prod_key"]
}
}
Run Code Online (Sandbox Code Playgroud) android android-manifest android-studio android-gradle-plugin
我正在测试我的应用程序Marshmallow 6.0
,它正在关闭android.permission.READ_EXTERNAL_STORAGE
,即使已经在Manifest中定义了它.在某处我读过,如果我在运行时请求权限,那么它就不会强行关闭你的应用程序.我也读过这个android文档,用于请求运行时权限.
所以,我开始知道我们可以请求android文档中提到的下面的权限.
// Here, thisActivity is the current activity
if (ContextCompat.checkSelfPermission(thisActivity,
Manifest.permission.READ_CONTACTS)
!= PackageManager.PERMISSION_GRANTED) {
// Should we show an explanation?
if (ActivityCompat.shouldShowRequestPermissionRationale(thisActivity,
Manifest.permission.READ_CONTACTS)) {
// Show an expanation to the user *asynchronously* -- don't block
// this thread waiting for the user's response! After the user
// sees the explanation, try again to request the permission.
} else {
// No explanation needed, we can request the permission.
ActivityCompat.requestPermissions(thisActivity,
new String[]{Manifest.permission.READ_CONTACTS},
MY_PERMISSIONS_REQUEST_READ_CONTACTS); …
Run Code Online (Sandbox Code Playgroud) 在我的应用程序使用AsyncTask
在oncreate
.有时我会在日志中看到"启动超时已过期,放弃唤醒锁定!历史记录的活动空闲超时".这可能导致任何问题,或者我们可以忽略这一点?
嗨我尝试生成签名的apk 1次测试,现在我只想刺激测试设备但Android工作室总是生成签名apk.这将使进程更长(每次我按下运行按钮android studio将自动生成签名apk)如何禁用自动生成签名的apk?我只是想在模拟器上运行应用程序?
我使用导航抽屉在eclipse中创建了一个新项目,而不是屏幕左上角的三行图标,我有后退箭头图标.我在堆栈上没有发现什么东西似乎有帮助.我试图改变setDisplayHomeAsUpEnabled
,setHomeButtonEnabled
但它没有帮助这里是代码的一部分(顺便说一下它的默认代码来自eclipse)任何人有想法?
正如Android文档所说
Snackbars提供有关操作的轻量级反馈.它们在移动屏幕底部显示简短消息,在较大设备上显示左下方.
我们可以snackbars
在屏幕顶部而不是底部显示任何替代方案吗?
现在我正在做这样的事情,它显示snackbar
在屏幕的底部.
Snackbar.make(findViewById(android.R.id.content), "Hello this is a snackbar!!!",
Snackbar.LENGTH_LONG).setAction("Undo", mOnClickListener)
.setActionTextColor(Color.RED)
.show();
Run Code Online (Sandbox Code Playgroud) String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) this.getSystemService(ns);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = title;
long when = System.currentTimeMillis();
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
if(alarmSound == null){
alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
}
}
Intent intent = new Intent();
PendingIntent pendingIntent
= PendingIntent.getActivity(this, 0, intent, 0);
NotificationCompat.BigTextStyle bigxtstyle =
new NotificationCompat.BigTextStyle();
bigxtstyle.bigText(text);
bigxtstyle.setBigContentTitle(title);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setStyle(bigxtstyle)
.setSmallIcon(icon)
.setAutoCancel(true)
.setSound(alarmSound)
.setDeleteIntent(pendingIntent)
.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(), 0));
Notification noti = mBuilder.build();
mNotificationManager.notify(notificationid++, noti);
Run Code Online (Sandbox Code Playgroud)
此代码有效,并显示通过自动换行宣传的文本.但是,当后续通知发生时,先前的通知会丢失其文本.有人可以帮忙解决这个问题吗?它可能是我设置不正确的东西,我是android …