小编too*_*o42的帖子

如何在Android上自定义AutoCompleteTextView下拉列表

我想知道如果可以的话,从AutoCompleteTextView选择时自定义下拉列表的颜色.我可以自定义其他所有内容,但不能选择所选颜色,即 - 它保持不变.

Activity:

ArrayAdapter<String> adap = new ArrayAdapter<String>(this, R.layout.row, strings);
autoNewBird = (AutoCompleteTextView)findViewById(R.id.autoCompleteBirdName);
autoNewBird.setAdapter(adap);
Run Code Online (Sandbox Code Playgroud)

row.xml:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/birdtext"
android:padding="5dip"  
android:background="@drawable/custom_spinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="@style/spinner_item" 
android:gravity="center_vertical"
android:layout_gravity="center_vertical" android:lines="1"/>
Run Code Online (Sandbox Code Playgroud)

和drawable custom_spinner.xml(在drawable文件夹中)

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/listback" />
<item android:state_window_focused="false" android:state_enabled="false"
    android:drawable="@drawable/listback" />
<item android:state_pressed="true" android:drawable="@drawable/threebythree" />
<item android:state_enabled="true" android:state_focused="true"
android:drawable="@drawable/threebythree" />              
<item android:state_enabled="true" android:drawable="@drawable/listback" />
<item android:state_focused="true" android:drawable="@drawable/listback" />
<item android:drawable="@drawable/listback" />
</selector>
Run Code Online (Sandbox Code Playgroud)

这适用于微调器下拉列表,但对于AutoCompleteTextView选中,它不会像微调器下拉列表那样改变颜色.

任何帮助,或经验与此将不胜感激.

android autocompletetextview drop-down-menu

14
推荐指数
2
解决办法
2万
查看次数

Espresso Tests无法访问类文件

我尝试运行ui测试时遇到以下错误.

/Users/etiennelawlor/workspace/MovieHub/app/src/androidTest/java/com/etiennelawlor/moviehub/MoviesFragmentTest.java 

Error:(34, 28) error: cannot access AppCompatActivity class file for android.support.v7.app.AppCompatActivity not found 

Error:(34, 58) error: cannot infer type arguments for ActivityTestRule<> 

Error:(41, 41) error: cannot access IdlingResource class file for android.support.test.espresso.IdlingResource not found 

Error:(51, 40) error: cannot access RecyclerView class file for android.support.v7.widget.RecyclerView not found 

Error:Execution failed for task ‘:app:compileDebugAndroidTestJavaWithJavac’.
Compilation failed; see the compiler error output for details.
Run Code Online (Sandbox Code Playgroud)

这是我的测试类:https://github.com/lawloretienne/MovieHub/blob/226492727e4d467b337ed4b689edb05eec0368c2/app/src/androidTest/java/com/etiennelawlor/moviehub/MoviesFragmentTest.java

我错过了什么吗?

这是我的Gradle文件

https://github.com/lawloretienne/MovieHub/blob/master/app/build.gradle

android ui-testing android-espresso

14
推荐指数
1
解决办法
929
查看次数

带有由LoaderManager管理的自定义适配器的AlphabetIndexer

我试图AlphabetIndexer用这样的自定义适配器实现

带自定义适配器的AlphabetIndexer

我的类ContactsCursorAdapter扩展SimpleCursorAdapter和实现SectionIndexer ,我使用a LoaderManager来管理我的适配器的光标,所以我已经覆盖了swapCursor()方法,就像上面示例的第二个答案所示.

public class ContactsCursorAdapter extends SimpleCursorAdapter 
    implements SectionIndexer{

    private LayoutInflater mInflater;
    private Context mContext; 

    private AlphabetIndexer mAlphaIndexer;

    public ContactsCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to) {
        super(context, layout, c, from, to);

        mInflater = LayoutInflater.from(context);
        mContext = context;
    }

    public View getView(final int position, View convertView, ViewGroup parent) {
        ...
    }

    @Override
    public int getPositionForSection(int section) {
        return mAlphaIndexer.getPositionForSection(section);
    }

    @Override
    public int getSectionForPosition(int position) { …
Run Code Online (Sandbox Code Playgroud)

android adapter simplecursoradapter android-loadermanager android-cursorloader

11
推荐指数
1
解决办法
1万
查看次数

覆盖引用的样式属性

阅读参考主题属性后,我试图在我设置的自定义主题中引用属性的值.

我将用户定义的样式应用于 CheckedTextView

<CheckedTextView
    android:id="@+id/contactInfo"
    style="@style/ListViewCheckedTextViewRowStyle" >
</CheckedTextView>
Run Code Online (Sandbox Code Playgroud)

用户定义的样式定义为:

<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
    <item name="android:checkMark">?android:listChoiceIndicatorMultiple</item>
</style>
Run Code Online (Sandbox Code Playgroud)

我创建的主题定义为:

<style name="Theme.Yellowgreen" parent="android:Theme.Holo.Light.DarkActionBar">
    <item name="android:listChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但是,显示的checkMark样式是设备的默认主题的drawable,而不是我的用户定义的drawable.

我可以显示可绘制的唯一方法是:

<style name="ListViewCheckedTextViewRowStyle" parent="@style/ListViewRowStyle">
    <item name="android:checkMark">@drawable/btn_check_holo_light</item>
</style>
Run Code Online (Sandbox Code Playgroud)

但这违背了覆盖此属性的整个目的,特别是因为我想在多个主题中覆盖此属性.

我在onCreate()我的方法中设置主题Activity:

public void onCreate(Bundle savedInstanceState) {
    this.setTheme(R.style.Theme_Yellowgreen);
    super.onCreate(savedInstanceState);
    // ...
}
Run Code Online (Sandbox Code Playgroud)

我还尝试在AndroidManifest.xml文件中设置主题,如:

<application android:theme="@style/Theme.Yellowgreen" >
Run Code Online (Sandbox Code Playgroud)

但那没用.怎么可能出错?

更新

我刚刚创建了一个小型示例项目,看起来我上面发布的代码正在运行.所以我必须有一些其他样式覆盖这个属性,或者它可能与我的布局xml文件有关.

在我的大项目中,我有两个FragmentsActivity.两者Fragments都有Listviews支持Adapters.在Fragment A所述getView()的方法Adapter如下:

public View getView(final int position, View convertView, …
Run Code Online (Sandbox Code Playgroud)

android themes styles overriding checkedtextview

9
推荐指数
1
解决办法
3万
查看次数

Android PendingIntent附加功能,未被BroadcastReceiver接收

当我将额外内容传递给PendingIntent时,sendBroadcastReceiver永远不会收到该消息,因为永远不会调用onReceive()此方法BroadcastReceiver.为什么会这样?

public class MainActivity extends Activity {
    private static String SENT = "SMS_SENT";
    private static String DELIVERED = "SMS_DELIVERED";
    private static int MAX_SMS_MESSAGE_LENGTH = 160;

    private static Context mContext;
    private BroadcastReceiver sendBroadcastReceiver, deliveryBroadcastReceiver;
    private final String DEBUG_TAG = getClass().getSimpleName().toString();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // ---when the SMS has been sent---
        sendBroadcastReceiver = new BroadcastReceiver() {

            public void onReceive(Context arg0, Intent arg1) {
                switch (getResultCode()) {
                    case Activity.RESULT_OK:
                        Toast.makeText(getBaseContext(), "SMS Sent", Toast.LENGTH_SHORT).show();
                        break;
                    case …
Run Code Online (Sandbox Code Playgroud)

sms android broadcastreceiver android-pendingintent

6
推荐指数
1
解决办法
1万
查看次数

像ContextMenu一样获取PopupMenu的上下文

所以我的ExpandableListView组行定义如下:

group_row.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:id="@+id/GroupName"
        style="@style/ListViewRowStyle"
        android:paddingLeft="40dp"
        android:textSize="18sp" >
    </TextView>

    <ImageView
        android:id="@+id/Menu"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_marginTop="10dp"
        android:contentDescription="@string/default_content_description_text"
        android:src="@drawable/ic_menu_moreoverflow_normal_holo_light" >
    </ImageView>

</RelativeLayout> 
Run Code Online (Sandbox Code Playgroud)

当您单击TextView它时,它将展开或折叠,具体取决于当前是否显示子行.我附上了OnClickListenerImageView组一行.ImageView单击此按钮时,我会启动PopupMenu如下图像:

在此输入图像描述

在此输入图像描述

一旦PopupMenu显示和动作中的一个被点击,我想在该组的所有儿童执行操作.问题是我无法确定ImageView单击的行.

我弄清楚如何将动作应用于所有孩子的唯一方法是使用ContextMenu如下图像:

在此输入图像描述

我想避免使用a,ContextMenu因为组行上的LongClick可能不明显,用户无法确定它会在子行上执行某些操作.我认为更明显的设计是将a锚定PopupMenuImageView(在我的情况下是菜单图标)并将操作应用于该组的子行.我怎样才能获得这个功能PopupMenu

android contextmenu popupmenu expandablelistview onclicklistener

6
推荐指数
1
解决办法
1万
查看次数

EditText不接受数字作为输入

EditText与观点id="price"有一个inputType="numberDecimal"不接受任何数字,但只接受一个小数点.另一个EditText视图id="store"没有inputType设置,但有两个问题.如果视图没有输入,则从键盘输入数字不会执行任何操作.接受数字的唯一方法是紧跟一个字母或另一个数字.我正在使用默认Android键盘.布局在onCreateView()子类的方法中被夸大了SherlockFragment.这可能是一个问题与EditText内部的视图行为SherlockFragment?我有一个类似的布局用于膨胀'SherlockFragmentActivity'的子类,这些EditText视图表现正常.有谁知道可能导致这个问题的原因是什么?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent" 
              android:layout_height="match_parent" 
              android:orientation="vertical">
    <TextView 
        style="@style/ProductTextViewTitle"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"
        android:padding="10dp" 
        android:text="Product Tile" />
    <TableRow android:layout_width="fill_parent" 
              android:layout_height="50dp"     
              android:gravity="center_vertical"
              android:padding="5dp">
        <TextView 
              style="@style/ApolloStyleBold"
              android:layout_width="0dp" 
              android:layout_height="match_parent" 
              android:layout_weight="0.4"
              android:gravity="center_vertical" 
              android:paddingLeft="5dp" 
              android:text="@string/price"/>
        <EditText android:id="@+id/price" 
                  android:layout_width="0dp" 
                  android:layout_height="match_parent"
                  android:layout_weight="0.6" 
                  android:background="@null" 
                  android:hint="@string/price_italic_hint"
                  android:inputType="numberDecimal"/>
    </TableRow>
    <TableRow android:layout_width="fill_parent" 
              android:layout_height="50dp"    
              android:gravity="center_vertical"
              android:padding="5dp">
        <TextView   
            style="@style/ApolloStyleBold"
            android:layout_width="0dp" 
            android:layout_height="match_parent" 
            android:layout_weight="0.4"
            android:gravity="center_vertical" 
            android:paddingLeft="5dp" 
            android:text="@string/store_name"/>
        <EditText android:id="@+id/store" 
                  android:layout_width="0dp" 
                  android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

android android-edittext actionbarsherlock

6
推荐指数
1
解决办法
3292
查看次数

记录 WorkManager 工作人员

我正在尝试获取有关 WorkManager我在应用程序中运行的工作人员的一些日志记录信息。我正在使用的版本2.4.0-alpha01使用了 Android 框架团队添加的新诊断功能

https://developer.android.com/jetpack/androidx/releases/work#2.4.0-alpha01

他们指示我运行以下命令

adb shell am broadcast -a "androidx.work.diagnostics.REQUEST_DIAGNOSTICS" -p "<your_app_package_name>"

当我执行这个命令时它只是回显

Broadcast completed: result=0 
Run Code Online (Sandbox Code Playgroud)

到航站楼

然后他们告诉我,我应该通过运行来查看 logcat 中的诊断信息

adb logcat

我运行了该命令,日志的输出看起来像是被混淆了,而且我没有看到任何特定于我的工作人员的日志。

您如何解析这些日志以获取有关您的 WorkManager Workers 的信息?

更新

我现在看到了 WorkManager 日志,因为我已WM-在 logcat 中添加了搜索关键字。

我注意到我的一些工人已经停止运行,但我不明白为什么。

这些是从最后一个成功的工作人员开始的日志

2020-04-27 10:52:32.439 com.sampleapp.android.staging.debug D/WM-StopWorkRunnable: StopWorkRunnable for 58c8d95c-4cbc-4a85-aa18-a93e9926019a; Processor.stopWork = false
2020-04-27 10:52:35.304 com.sampleapp.android.staging.debug D/WM-WorkerWrapper: com.sampleapp.android.common.workers.DownloadMediaWorker returned a Success {mOutputData=Data {MEDIA_ITEM_ID : 16503, }} result.
2020-04-27 10:52:35.308 com.sampleapp.android.staging.debug I/WM-WorkerWrapper: Worker result SUCCESS for Work [ id=b892f6fc-79e4-4475-8da6-d151f217bf59, tags={ com.sampleapp.android.common.workers.DownloadMediaWorker, DOWNLOAD_MEDIA_ITEM_16_1_1 …
Run Code Online (Sandbox Code Playgroud)

android worker logcat deobfuscation android-workmanager

6
推荐指数
1
解决办法
1355
查看次数

ActionBarSherlock堆叠动作栏样式问题

我无法弄清楚为什么ActionBar我实现的堆叠在最左边的标签和屏幕边缘之间有一个间隙.

最左边的标签有左边的分隔符问题

最右边的选项卡不是这种情况.

最右边的选项卡没有分隔符问题

我试图通过造型来移除分隔线ActionBar.在玩了一点风格之后,似乎我能够覆盖TabView样式的属性而不是TabBar样式ActionBarSherlock.

<style name="ActionBarTabBarStyle.Dark" parent="@style/Widget.Sherlock.ActionBar.TabBar">
    <item name="android:divider">@null</item>
    <item name="android:showDividers">none</item>
    <item name="android:dividerPadding">0dip</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后我意识到我需要包含相同的无前缀属性.

ActionBarSherlock主题

Due to limitations in Android's theming system any theme customizations must be declared 
in two attributes. The normal android-prefixed attributes apply the theme to the native 
action bar and the unprefixed attributes are for the custom implementation. Since both 
theming APIs are exactly the same you need only reference your customizations twice rather 
than having to implement …
Run Code Online (Sandbox Code Playgroud)

android theming actionbarsherlock android-actionbar android-styles

5
推荐指数
1
解决办法
4875
查看次数

Dagger2可用于单元测试和仪表测试吗?

https://developer.android.com/studio/test/index.html 您是否可以使用Dagger2 Local unit tests(位于module-name/src/test/java /.),Instrumented tests(位于module-name/src/androidTest/java /.)或两者兼而有之?

这有什么例子吗?

android unit-testing dagger-2

5
推荐指数
1
解决办法
698
查看次数

Android闹钟UI

在此输入图像描述

我想弄清楚UI是如何为Android闹钟应用程序设计的.这似乎是使用Holo Dark Theme.

包含的屏幕截图是"创建/编辑警报" Activity屏幕.它看起来类似于Android设置.这种情况?因为"打开闹钟"和"振动"行看起来像ChexboxPreferences."铃声"行看起来像一个RingtonePreference.那个"时间"排怎么样?

正如@eric在评论中提到的以下答案之一,我正在尝试重新创建一个类似于闹钟应用程序的界面.我不想发送从我的应用程序启动Alarm Manager的意图.

那么"标签"行怎么样?这很像一个EditText视图.你有一个xml标签的组合ViewsPreferences内部PreferenceScreen吗?

还有ActionBar一个垂直管道,我不知道这是如何创建但是"完成"视图ImageButton

我并不完全相信它是首选项的组合,因为Alarm应用程序可以有多个警报而不仅仅是一个警报.如果有多个警报并且您不使用多个SharedPreferences文件,则创建内容提供程序以存储与多个警报相关的信息自然是有意义的.

settings user-interface android alarm android-preferences

4
推荐指数
1
解决办法
1万
查看次数

在相对URL上改进尾随斜杠

是否Retrofit从端点的相对URL中删除尾部斜杠?我尝试在我的一个端点上添加尾部斜杠但是当我单步调试并查看Call对象时,如果我钻入delete.relativeUrl,它不会显示尾部斜杠.

endpoint trailing-slash retrofit retrofit2

2
推荐指数
1
解决办法
1644
查看次数

在 android 上解析应用程序/smil MMS MIME 类型

所以我遇到了三类彩信类型:

Plain Text - "text/plain"

Image - "image/jpeg", "image/bmp", "image/gif", "image/jpg", "image/png"

SMIL (Synchronized Multimedia Integration Language) - "application/smil"

所以我在获取属于前两类的 MMS 中的数据时没有问题。但是我无法从消息类型的 MMS 中获取数据 application/smil

下面我列出application/smil了我从手机中提取的5 个不同的彩信示例。

[31, 22, -1, application/smil, 123_1.smil, 106, null, null, <0000>, 0.smil, null, null, null, <smil>
  <head>
    <layout>
      <root-layout height="160" width="240"/>
      <region fit="meet" height="67%" id="Image" left="0%" top="0%" width="100%"/>
      <region fit="meet" height="33%" id="Text" left="0%" top="67%" width="100%"/>
    </layout>
  </head>
  <body>
    <par dur="8000ms">
      <img region="Image" src="cid:992"/>
    </par>
    <par dur="8000ms">
      <img region="Image" src="cid:993"/>
    </par>
  </body>
</smil>]
Run Code Online (Sandbox Code Playgroud)

. …

sms android mms mime-types

1
推荐指数
1
解决办法
5万
查看次数