如何创建选项菜单,如下面的屏幕截图所示:
单击RecyclerView项目的"更多"-Icon后,应打开选项菜单!
我的尝试是这样的:
@Override
public void onBindViewHolder(Holder holder, int position) {
holder.txvSongTitle.setText(sSongs[position].getTitle());
holder.txvSongInfo.setText(sSongs[position].getAlbum() + " - " + sSongs[position].getArtist());
holder.btnMore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(mContext, "More...", Toast.LENGTH_SHORT).show();
}
});
}
Run Code Online (Sandbox Code Playgroud)
但这会导致问题,因为如果我触摸RecyclerView项目更多按钮,则单击完整项目...
这是我的RecyclerViewOnTouchListener:
public class RecyclerViewOnTouchListener implements RecyclerView.OnItemTouchListener {
private GestureDetector mGestureDetector;
private OnTouchCallback mOnTouchCallback;
public RecyclerViewOnTouchListener(Context context, final RecyclerView recyclerView, final OnTouchCallback onTouchCallback) {
mOnTouchCallback = onTouchCallback;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
@Override
public void …Run Code Online (Sandbox Code Playgroud) Android的谷歌应用程序有一个通知,显示当地的天气.如果您在通知上向左滑动,它会显示"时钟图标"-action(例如,贪睡),如下所示.
如果单击时钟,将打开以下下拉菜单:
这是android系统的一个功能,我想在我的应用程序中实现.它应该通过通知操作打开,我想设置自定义选项,我需要获取选定的值.
有谁知道如何实现它?
我正在使用 AS 3.4.1 和运行 Android 9 的模拟器进行测试。
当我Room Dao Function annotated with @Transaction在其中使用 a 时,以下测试将无法运行。
class RecurrenceManagerTest : DatabaseTest() {
@Rule
@JvmField
val instantTaskExecutorRule = InstantTaskExecutorRule()
var recurringEntryId: Long = -1
@Before
override fun setup() {
super.setup() // only initialized the db
val recurringEntry = RecurringEntry(
recurrence = Recurrence(DATE.toEpochMilli(), Recurrence.DAILY)
)
recurringEntryId = runBlocking { db.recurringEntryDao().insert(recurringEntry) }
val recurringBookEntry = BookEntry.create(
title = TITLE,
date = DATE,
value = VALUE,
isPaid = IS_PAID,
notes = NOTES,
entryType = …Run Code Online (Sandbox Code Playgroud) android kotlin android-room android-architecture-components kotlin-coroutines
我在 Outlook for Android 应用程序中看到了这个新的 Snackbar 样式,现在在材料文档中寻找它:
https://material.io/design/components/snackbars.html
有人知道如何创建那些“偏移小吃店”吗?
android material-design snackbar android-snackbar material-components-android
我正在使用 Room 和 Paging 库来显示类别。
我的实体:
@Entity(tableName = Database.Table.CATEGORIES)
data class Category(
@PrimaryKey(autoGenerate = true) @ColumnInfo(name = ID) var id: Long = 0,
@ColumnInfo(name = NAME) var name: String = "",
@ColumnInfo(name = ICON_ID) var iconId: Int = 0,
@ColumnInfo(name = COLOR) @ColorInt var color: Int = DEFAULT_COLOR
)
Run Code Online (Sandbox Code Playgroud)
我的道:
@Query("SELECT * FROM $CATEGORIES")
fun getPagedCategories(): DataSource.Factory<Int, Category>
@Update
fun update(category: Category)
Run Code Online (Sandbox Code Playgroud)
我的回购:
val pagedCategoriesList: LiveData<PagedList<Category>> = categoryDao.getPagedCategories().toLiveData(Config(CATEGORIES_LIST_PAGE_SIZE))
Run Code Online (Sandbox Code Playgroud)
我的视图模型:
val pagedCategoriesList: LiveData<PagedList<Category>>
get() = repository.pagedCategoriesList
Run Code Online (Sandbox Code Playgroud)
我的适配器:
class CategoriesAdapter(val context: Context) …Run Code Online (Sandbox Code Playgroud) android android-adapter kotlin android-recyclerview android-paging
我正在尝试通过 robolectric 运行我的 android 测试,但它收到以下错误消息:
at.guger.moneybook.data.repository.AccountsRepositoryTest STANDARD_ERROR
[Robolectric] WARN: Android SDK 16 requires Java 8 (have Java 1). Tests won't be run on SDK 16 unless explicitly requested.
[Robolectric] WARN: Android SDK 17 requires Java 8 (have Java 1). Tests won't be run on SDK 17 unless explicitly requested.
[Robolectric] WARN: Android SDK 18 requires Java 8 (have Java 1). Tests won't be run on SDK 18 unless explicitly requested.
[Robolectric] WARN: Android SDK 19 requires Java 8 (have Java …Run Code Online (Sandbox Code Playgroud) 我的应用程序有一个静态快捷方式,我正在使用导航体系结构组件。
我正在使用以下实现,但在Android 9上不起作用。
在我的MainActivity中:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
setupToolbar()
setupNavigationDrawer()
checkPermissions()
if (intent.action == MoneyBook.SHORTCUT_ACTION_ADD_BOOKENTRY) {
findNavController(R.id.nav_host_fragment).popBackStack(R.id.action_entriesFragment_to_newBookEntryFragment, false)
}
}
Run Code Online (Sandbox Code Playgroud)
shortcuts.xml:
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android">
<shortcut
android:enabled="true"
android:icon="@drawable/ic_shortcut_addbookentry"
android:shortcutId="shortcut_addbookentry"
android:shortcutLongLabel="@string/shortcut_addbookentry_label_short"
android:shortcutShortLabel="@string/shortcut_addbookentry_label_short">
<intent
android:action="at.guger.moneybook.action.ADD_BOOKENTRY"
android:targetClass="at.guger.moneybook.activity.MainActivity"
android:targetPackage="at.guger.moneybook.dev" />
</shortcut>
</shortcuts>
Run Code Online (Sandbox Code Playgroud)
在调试应用程序时,我注意到该findNavController(...)方法已调用,但屏幕上没有任何反应。
此外,我不会覆盖onStart(...)或onResume(...)。
有没有给定的方法来通过导航组件实现应用程序快捷方式,或者我在这里做错了什么?
android kotlin android-appshortcut android-architecture-components android-jetpack
我在 RecyclerView 中添加了一个 FastScroller 并使用了一个“气泡”-Drawable。
如果我在 API 21 上测试我的应用程序,它可以工作,但如果我在 API 19 上测试它,它会崩溃:
java.lang.RuntimeException: 无法启动活动 ComponentInfo{at.guger.musixs/at.guger.musixs.ui.MainActivity}:
android.view.InflateException:二进制 XML 文件第 15 行:错误膨胀类 at.guger.fastscroll.FastScroller ... 引起:android.view.InflateException:二进制 XML 文件第 15 行:错误膨胀类 at.guger.fastscroll .FastScroller
...引起:java.lang.reflect.InvocationTargetException
... 引起:android.view.InflateException:二进制 XML 文件第 6 行:错误膨胀类 at.guger.fastscroll.FastScrollBubble
...引起:java.lang.reflect.InvocationTargetException
... 引起:android.content.res.Resources$NotFoundException: File res/drawable/bubble.xml from drawable resource ID #0x7f02004b
在 android.content.res.Resources.loadDrawable(Resources.java:3457)
在 android.content.res.TypedArray.getDrawable(TypedArray.java:602)
在 android.view.View.(View.java:3767)
在 android.view.ViewGroup.(ViewGroup.java:481)
在 android.widget.FrameLayout.(FrameLayout.java:101)
在 android.widget.FrameLayout.(FrameLayout.java:97)
在 at.guger.fastscroll.FastScrollBubble.(FastScrollBubble.java:0)
... 38
我的气泡 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:topLeftRadius="@dimen/bubble_corner_radius"
android:topRightRadius="@dimen/bubble_corner_radius"
android:bottomLeftRadius="@dimen/bubble_corner_radius"
android:bottomRightRadius="0dp" />
<solid android:color="?attr/colorAccent" …Run Code Online (Sandbox Code Playgroud) 我在使用Application-Theme更改Background-Color时遇到问题.
NotificationCompat.Builder nBuilder = new NotificationCompat.Builder(this);
TypedValue typedValue = new TypedValue();
getTheme().resolveAttribute(R.attr.colorPrimary, typedValue, true);
int iPrimaryColor = typedValue.data;
getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true);
int iPrimaryDarkColor = typedValue.data;
Intent notIntent = new Intent(getApplicationContext(), MainActivity.class);
notIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent notOpenOnClick = PendingIntent.getActivity(getApplicationContext(), 0, notIntent, PendingIntent.FLAG_UPDATE_CURRENT);
RemoteViews smallContentView = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews bigContentView = new RemoteViews(getPackageName(), R.layout.notification_expanded);
nBuilder.setSmallIcon(R.drawable.not_icon)
.setOngoing(true)
.setContentTitle(getCurrentSong().getTitle())
.setContentIntent(notOpenOnClick);
Notification not = nBuilder.build();
smallContentView.setInt(R.id.not_linLayout, "setBackgroundColor", iPrimaryColor);
smallContentView.setInt(R.id.not_imvDivider, "setBackgroundColor", iPrimaryDarkColor);
bigContentView.setInt(R.id.not_linLayout, "setBackgroundColor", iPrimaryColor);
bigContentView.setInt(R.id.not_imvDivider, "setBackgroundColor", iPrimaryDarkColor);
setListeners(smallContentView);
setListeners(bigContentView);
not.contentView = smallContentView;
not.bigContentView = bigContentView;
if …Run Code Online (Sandbox Code Playgroud) 我正在通过以下方式在我的应用程序中向/从 ArrayList 添加/删除项目:
public long gotoItem(int pos) {
if (pos > 0) {
List<QueueItem> mSubList = mItems.subList(0, pos);
switch (mRepeatType) {
case NO_REPEAT:
case REPEAT_SINGLE:
mPlayedItems.addAll(mSubList);
mItems.removeAll(mSubList);
break;
case REPEAT_ALL:
mItems.removeAll(mSubList);
mItems.addAll(mSubList);
break;
}
}
return (long) mItems.get(0).getItem();
}
Run Code Online (Sandbox Code Playgroud)
我得到以下异常抛出:
> java.util.ConcurrentModificationException at java.util.AbstractList$SubAbstractList.listIterator(AbstractList.java:314)
at java.util.AbstractList$SubAbstractList.iterator(AbstractList.java:301)
at java.util.AbstractCollection.contains(AbstractCollection.java:127)
at java.util.AbstractCollection.removeAll(AbstractCollection.java:277)
at at.guger.musixs.playback.queue.Queue.gotoItem(Queue.java:135)
at at.guger.musixs.playback.MusicService.gotoPosition(MusicService.java:500)
at at.guger.musixs.playback.MusicPlayer.gotoPosition(MusicPlayer.java:138)
at at.guger.musixs.activity.MainActivity.SyncLocation(MainActivity.java:707)
at at.guger.musixs.activity.MainActivity.access$200(MainActivity.java:73)
at at.guger.musixs.activity.MainActivity$1.onServiceConnected(MainActivity.java:605)
at at.guger.musixs.playback.MusicPlayer$ServiceBinder.onServiceConnected(MusicPlayer.java:246)
at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1224)
at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1241)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at …Run Code Online (Sandbox Code Playgroud) 我正在研究开发一个开源应用程序,它将在未来获得同步功能。
这将通过 Firebase Firestore 实现。此功能仅适用于通过 Google Play Billing 订阅 abonnement 的用户。
现在,如果我将我的google-services.json代码上传到我的开源存储库,任何人都可以编译应用程序并删除检查,无论是否有有效订阅。
但是如果我不上传我的google-services.json.CircleCI 无法构建我的项目,因为文件丢失了。
有没有人有这方面的经验,或一些提示?
谢谢!
android ×11
kotlin ×4
android-architecture-components ×2
java ×2
android-room ×1
arraylist ×1
google-play ×1
iterator ×1
list ×1
material-components-android ×1
robolectric ×1
service ×1
snackbar ×1
themes ×1
unit-testing ×1
xml ×1