小编SjN*_*erd的帖子

将自定义视图添加到工具栏

我正在尝试将自定义视图添加到新工具栏(Lollipop).但不知何故,视图会添加到工具栏下方.我使用actionBar.setCustomView时工作正常,但现在迁移到工具栏后,它不起作用.下面是代码.应该做些什么改变?

片段:

    toolbar = (Toolbar) getView().findViewById(R.id.toolbar);
    ((ActionBarActivity) getActivity()).setSupportActionBar(toolbar);

    toolbar.setTitle(getString(R.string.app));



    ActionBar actionBar = ((ActionBarActivity) getActivity())
            .getSupportActionBar();

    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 

    LayoutInflater inflater = (LayoutInflater) getActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    // inflate the view
    final View view = inflater.inflate(R.layout.actionbar_search, null);
    final ImageView searchIcon = (ImageView) view
            .findViewById(R.id.search_icon);
    final ClearableAutoCompleteTextView searchBox = (ClearableAutoCompleteTextView) view
            .findViewById(R.id.search_box);

    // start with the text view hidden in the action bar
    searchBox.setVisibility(View.INVISIBLE);
    searchIcon.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            toggleSearch(false, view);
        }
    });

    searchBox.setOnClearListener(new OnClearListener() {

        @Override
        public void onClear() {
            toggleSearch(true, …
Run Code Online (Sandbox Code Playgroud)

android android-toolbar

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

PopupMenu单击导致RecyclerView滚动

我有一个内部的溢出按钮CardViewRecyclerview.每当我点击按钮时,我会显示一个弹出菜单,但也会RecyclerView向下滚动一个项目.谁能帮助我阻止这种不必要的滚动?

基本上我试图复制与Playstore中相同的溢出按钮行为.

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">

<android.support.v7.widget.CardView
    android:id="@+id/cv_tracks"
    android:layout_width="match_parent"
    android:layout_height="65dp"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:id="@+id/ivTracks"
            android:layout_width="60dp"
            android:layout_height="60dp"
            android:background="@drawable/unknown"
           />
        <Button
            android:id="@+id/imgbtn_overflow"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:drawableTop="@drawable/ic_overflow"
            android:paddingLeft="25dp"
            android:paddingRight="20dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true" /> 
 </RelativeLayout>
 </android.support.v7.widget.CardView>
 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

适配器:

@Override
public void onBindViewHolder(final TracksViewHolder tracksViewHolder, int i) {

    tracksViewHolder.imgBtnOverflow.setTag(i);
    tracksViewHolder.imgBtnOverflow.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //Creating the instance of PopupMenu
            final int position = (Integer) v.getTag();

            PopupMenu popup = new PopupMenu(mContext,tracksViewHolder.imgBtnOverflow);

            //Inflating the …
Run Code Online (Sandbox Code Playgroud)

android popupmenu android-recyclerview

13
推荐指数
2
解决办法
2558
查看次数

将SVG图像解码为位图

我正在使用Android Studio将我的SVG图像转换为XML文件.当我尝试使用R.drawable.svgimage访问它时它工作正常,但现在我需要将该图像解码为位图.

我尝试了以下内容.它为位图返回null.

mResId = R.drawable.svgimage
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeResource(
            mContext.getResources(), mResId, options); 
Run Code Online (Sandbox Code Playgroud)

svg android bitmap

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

以编程方式更改锁定屏幕背景

我正在尝试从我的应用程序更改锁定屏幕背景图像,但我无法弄清楚如何做到这一点.我成功地使用WallPaperManager更改了主屏幕壁纸,但找不到为锁定屏幕执行相同操作的源.我知道QuickPic和Stock Gallery这样的应用程序会这样做,所以我该如何实现呢?

这是我用来更改主屏幕的代码:

WallpaperManager myWallpaperManager = WallpaperManager
                .getInstance(getApplicationContext());

try {
    myWallpaperManager.setBitmap(bm);
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)

有人实施了这个请指出我正确的方向与我的应用程序这样做?

android lockscreen android-wallpaper

7
推荐指数
0
解决办法
1328
查看次数

针对strings.xml的Android Serbian拉丁语和黑山值文件夹

我正在尝试为塞尔维亚拉丁语(srpski)和黑山语(包括西里尔语和拉丁语)翻译strings.xml.我在值文件夹中包含了Serbian Cyrillic(српски)作为values-sr.它工作正常.但对于塞尔维亚拉丁语和黑山语,我无法确定值文件夹的名称应该是什么.我在SO中经历了很多帖子

如何更改语言环境以使用拉丁语塞尔维亚语(而不是西里尔语塞尔维亚语)

塞尔维亚语(拉丁语,塞尔维亚语)(sr-rs-latn)语言的值文件夹名称应该是什么?

但他们没有多大帮助.

我从https://github.com/championswimmer/android-locales了解到,值文件夹应该是:

塞尔维亚语(西里尔语)sr - > values-sr-r_#Cyrl

塞尔维亚语(西里尔语,黑山语)sr ME - > values-sr-rME_#Cyrl

塞尔维亚语(西里尔文,塞尔维亚)sr RS - > values-sr-rRS_#Cyrl

塞尔维亚语(拉丁语)sr - > values-sr-r_ #Tatn

塞尔维亚语(拉丁语,黑山语)sr ME - > values-sr-rME_#Latn

塞尔维亚语(拉丁语,塞尔维亚)sr RS - > values-sr-rRS_#Latn

但是如果我尝试在Android studio中创建像values-sr-rRS_#Latn这样的文件夹,则会抛出错误"Invalid directory".然后我开始进行一些分析.

  1. 在Nexus 9 Marshmallow中,使用Locale.getAvailableLocales()的可用语言环境列表列出了所有塞尔维亚语言.所以他们得到了支持.

    sr
    sr __#Cyrl
    sr_BA_#Cyrl
    sr_ME_#Cyrl
    sr_RS_#Cyrl
    sr_XK_#Cyrl
    sr __#Latn
    sr_BA_#Latn
    sr_ME_#Latn sr_RS_#Latn
    sr_XK_#Latn

  2. 在Nexus 9的设置屏幕中,我可以看到只能更改为塞尔维亚语西里尔语(српски)的选项,而在联想瑜伽选项卡中,我看到选项只能更改为塞尔维亚拉丁语(srpski).当我在两个设备中调试时,我发现两者都有sr 作为语言代码,RS作为区域代码,脚本代码是空白的.那么如何在app中包含两个值文件夹以及如何映射?

  3. 我应该为values-sr-ZZ创建值文件夹,还是为我需要的语言创建一些东西,并在代码中检查脚本代码?

  4. 但如果是这种情况,在Google Play游戏和设置应用的资源文件夹中,我发现他们只有一个值-sr文件夹.那么他们如何处理值-sr-r_#Latn和values-sr-rME_#Latn和values-sr-rME_#Cyrl.

有人可以指导我吗?

android locale localization

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

从播放列表中删除歌曲

我想从播放列表中删除一首歌.但不知道为什么不删除.这些是我在调试模式下检查的值:URI - content:// media/external/audio/playlists/4599/members
WHERE --audio_id =?
selectionArgs [] - [1214]

我在调试时发现控件在ContentResolver.class中跳过了这些行.

public final int delete(Uri url, String where, String[] selectionArgs)
{

    try {
        long startTime = SystemClock.uptimeMillis(); //skipped
        int rowsDeleted = provider.delete(mPackageName, url, where, selectionArgs);//skipped
        long durationMillis = SystemClock.uptimeMillis() - startTime;//skipped
        maybeLogUpdateToEventLog(durationMillis, url, "delete", where);
        return rowsDeleted;  // returns 0
    }
Run Code Online (Sandbox Code Playgroud)

在我的代码下方发布删除歌曲:

    public int deletePlaylistTracks(Context context, long playlistId,
        long audioId) {
    ContentResolver resolver = context.getContentResolver();
    int countDel = 0;
    Uri uri = MediaStore.Audio.Playlists.Members.getContentUri("external",
            playlistId);
            String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID
                + …
Run Code Online (Sandbox Code Playgroud)

android playlist

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

在实现接口时片段中的Onbackpressed不工作

我试图覆盖片段内的onbackpressed方法.但它给了我语法错误,它应该覆盖接口中的超级方法.为什么这样?我的片段类中还有其他方法,如ondestroy,但没有错误.为什么单独背压.我也试过onkeydown.同样的错误.粘贴在我的代码下面.

  public TestClass extends Fragment implements    Testinterface
{  @Override //error must override or implement    supertype method
 public void onBackPressed ()
{
 if (check)
Do somethin
 else
  getActivity().finish ()
  //super.onBackPressed () // error here if I use this
  }
Run Code Online (Sandbox Code Playgroud)

android android-fragments

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