我使用这个简单的代码在Android 4.1或更高版本中设置通知.它工作得很好,但我的问题是SmallIcon和LargeIcon.我知道SmallIcon显示在状态栏中,LargeIcon显示在下拉列表中.
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setTicker("The ticker");
builder.setContentTitle("The title");
builder.setContentText("The text");
builder.setSmallIcon(R.drawable.my_small_icon);
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.my_96px_large_icon);
builder.setLargeIcon(bm);
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.notify("direct_tag", NOTIF_ALERTA_ID, builder.build());
Run Code Online (Sandbox Code Playgroud)
我的问题是:
启动通知后,"The Ticker"文本旁边会显示一个裁剪的超大小图标,而不是显示原始SmallIcon而不会过大.

在下拉列表中,我看到左边的LargeIcon,这很好.但是我也会在通知时间旁边看到右边的小图标.我不想表明这一点.

我想在我的项目中添加菜单处理程序.我也阅读了http://developer.android.com/guide/topics/ui/menus.html,它非常简单,但图标未显示.我很迷茫.我甚至以编程方式添加了一个菜单项.
我的代码是:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 0, 0, "Quit").setIcon(R.drawable.ic_launcher);
getMenuInflater().inflate(R.layout.menu, menu);
return true;
}
Run Code Online (Sandbox Code Playgroud)
并在xml中:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
Set id, icon and Title for each menu item
-->
<item android:id="@+id/menu_bookmark"
android:icon="@drawable/update"
android:title="@string/Update" />
</menu>
Run Code Online (Sandbox Code Playgroud) a {...}和之间有什么区别a:link{...}?
它们之间有不同的用法和好处吗?
我有一个名为foo的变量和名为foo的函数.
//variable followed by function declaration
var foo="bar";
function foo(){
return "bar";
}
//function declaration followed by variable
function foo(){
return "bar";
}
var foo="bar";
//When I call foo it returns string bar;
//When I enquired foo() it throws error
Run Code Online (Sandbox Code Playgroud)
这里发生了什么?为什么变量名覆盖函数声明?
我有一个ListView使用自定义adaper(扩展BaseAdapter).如何添加滑动以删除手势?
我想使用gmail应用程序使用的相同功能.
我正在使用Android的聊天应用程序,我使用RecyclerView列出消息.
我已经编写了适配器,但是我在检测布局中的元素(本例中是TextView)被点击时遇到了问题.
这是我的适配器:
public class ChatRoomThreadAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private class ViewHolder extends RecyclerView.ViewHolder {
TextView message, timestamp;
private ViewHolder(View view) {
super(view);
message = (TextView) itemView.findViewById(R.id.message);
timestamp = (TextView) itemView.findViewById(R.id.timestamp);
}
}
public ChatRoomThreadAdapter(Context mContext, ArrayList<Message> messageArrayList, String userId) {
this.mContext = mContext;
this.messageArrayList = messageArrayList;
this.userId = userId;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView;
itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat, parent, false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
((ViewHolder) …Run Code Online (Sandbox Code Playgroud) 我试图找到一种简单的方法来将一个双精度数转换为两位小数.我使用BigDecimal来做这个技巧,但注意到doubleValuejava.math.BigDecimal类的功能不存在.
以下功能:
fun Double.roundTo2DecimalPlaces() =
BigDecimal(this).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()
Run Code Online (Sandbox Code Playgroud)
给我这个编译错误:
:compileKotlin
Using kotlin incremental compilation
w: The '-d' option with a directory destination is ignored because '-module' is specified
e: -{FilePathAndNameWereHere}-: (20, 14): Unresolved reference: doubleValue
:compileKotlin FAILED
Run Code Online (Sandbox Code Playgroud)
Kotlin版本是1.1.1
我正在为自己创造新的发射器.现在,当我从我的主要活动中运行应用程序时,它有这个默认动画,它将我的启动器放在后面并在其上弹出新应用程序.而不是这个,我想附加我自己的动画.最好我想默认从触摸点显示的素材动画.
到目前为止我尝试过的事情:
您需要在Android上使用此活动的Theme.AppCompat主题(或后代)
http://tips.androidhive.info/2015/09/android-how-to-apply-material-design-theme/
<style name="swLaunch" parent="swLaunch.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/explode</item>
<item name="android:windowSharedElementExitTransition">@android:transition/explode</item>
<item name="android:windowEnterAnimation">@android:transition/explode</item>
<item name="android:windowExitAnimation">@android:transition/explode</item>
<item name="android:taskToFrontEnterAnimation">@android:transition/explode</item>
<item name="android:taskToBackEnterAnimation">@android:transition/explode</item>
<item name="android:taskToFrontExitAnimation">@android:transition/explode</item>
<item name="android:taskToBackExitAnimation">@android:transition/explode</item>
<item name="android:inAnimation">@android:transition/explode</item>
<item name="android:layoutAnimation">@android:transition/explode</item>
<item name="android:windowShowAnimation">@android:transition/explode</item>
<item name="android:activityOpenEnterAnimation">@android:transition/explode</item>
<item name="android:fragmentOpenEnterAnimation">@android:transition/explode</item>
</style>
Run Code Online (Sandbox Code Playgroud)
这就是我启动应用程序的方式:
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.google.android.gm");
if (launchIntent != null) {
startActivity(launchIntent);
}
Run Code Online (Sandbox Code Playgroud) 我想使用GridView并根据文档,在适配器中我可以在适配器中使用此行:
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
Run Code Online (Sandbox Code Playgroud)
好吧,把它转换成Kotlin,它说:
它适用于Java,但不适用于Kotlin.
那么,为什么呢?我如何GridView.LayoutParams在Kotlin中使用?
我有一个 Android Studio 项目,其中包含 3 个模块。A、B、C。A 依赖于 C,B 依赖于 C。我试图加快构建时间,我意识到每次执行 assembleRelease/assembeDebug 任务时,它都会构建所有模块。每次我构建模块 A 应该只构建 A 和 C,因为 B 在那个任务中没有依赖,对吧?如何避免每次构建模块 A 时构建模块 B?
模块 A 依赖项:
dependencies {
compile project(path: ':c', configuration: 'release')
provided files('libs/some-lib.jar')
}
Run Code Online (Sandbox Code Playgroud)
模块 B 依赖项:
dependencies {
compile project(path: ':c', configuration: 'debug')
}
Run Code Online (Sandbox Code Playgroud)
模块 C 依赖项:
dependencies {
compile files('libs/other-lib.jar')
}
Run Code Online (Sandbox Code Playgroud) 我想用jQuery用图像替换文本.我一直在使用.replace函数替换更多文本的文本.如何用html标签替换文本,如<img>标签.
这是我的代码:
function wow() {
$('.messageBody').each(function() {
var text = $(this).text();
var image = '<img class = "emote" src = "trump.png">'
$(this).text(text.replace(':trump:', image.outterHTML));
});
}
setInterval(wow, 1000);
Run Code Online (Sandbox Code Playgroud)
这是HTML:
<span class="messageBody">:trump:</span>
Run Code Online (Sandbox Code Playgroud) 我正在开发一个Android Studio项目.其中一个活动是一个包含50个EditTexts的表单.由于有很多EditTexts,Activity的文件有超过1200行,一旦完成,还应该有300到400行.导航文件中的代码变得困难且耗时.
对于这种情况,我应该遵循哪些标准?现在最好的行动是什么?
android ×9
java ×2
javascript ×2
kotlin ×2
anchor ×1
build ×1
css ×1
dependencies ×1
gradle ×1
gridview ×1
html ×1
icons ×1
jquery ×1
listview ×1
optimization ×1
pseudo-class ×1
swipe ×1