小编End*_*ame的帖子

无法在独立视图上启动此动画师!揭示效果

我正在尝试在我的应用程序中创建显示效果,但没有成功.我想要的是当我打开一个片段时显示一个cardview.到目前为止我尝试的是:

private void toggleInformationView(View view) {
        infoContainer = view.findViewById(R.id.contact_card);

        int cx = (view.getLeft() + view.getRight()) / 2;
        int cy = (view.getTop() + view.getBottom()) / 2;
        float radius = Math.max(infoContainer.getWidth(), infoContainer.getHeight()) * 2.0f;

        if (infoContainer.getVisibility() == View.INVISIBLE) {
            infoContainer.setVisibility(View.VISIBLE);
            ViewAnimationUtils.createCircularReveal(infoContainer, cx, cy, 0, radius).start();
        } else {
            Animator reveal = ViewAnimationUtils.createCircularReveal(
                    infoContainer, cx, cy, radius, 0);
            reveal.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    infoContainer.setVisibility(View.INVISIBLE);
                }
            });
            reveal.start();
        }
    }
Run Code Online (Sandbox Code Playgroud)

并在onCreateView我开始的方法:

toggleInformationView(view);
Run Code Online (Sandbox Code Playgroud)

这是cardview:

<android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:id="@+id/contact_card"
        android:visibility="invisible" …
Run Code Online (Sandbox Code Playgroud)

java android android-animation

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

使用单选按钮列表创建自定义对话框

我有一个方法,我有一个值列表:

     /**
     * ISO
     * */
    public void getISO(View view) {
        // Open dialog with radio buttons
        List<String> supported_isos = preview.getSupportedISOs();
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
        String current_iso = sharedPreferences.getString(MainActivity.getISOPreferenceKey(), "auto");

    }
Run Code Online (Sandbox Code Playgroud)

此方法在onClick()上显示ImageButton:

android:onClick="getISO"
Run Code Online (Sandbox Code Playgroud)

但我需要在带有单选按钮的对话框中显示此列表.可能已在对话框中选择了首选项值.是否可能?

java android android-listview android-dialog

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

不要请求Window.FEATURE_ACTION_BAR问题

我正在尝试构建我的应用程序,但没有成功..我尝试了几种方式,但没有任何工作.例外是:

Caused by: java.lang.IllegalStateException: This Activity already has an action bar supplied by the window decor. Do not request Window.FEATURE_ACTION_BAR and set windowActionBar to false in your theme to use a Toolbar instead.
Run Code Online (Sandbox Code Playgroud)

我的style.xml是:

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light">

        <!-- theme customizations -->

        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowActionBar">false</item>

        <item name="android:textColorPrimary">@color/ldrawer_color</item>
        <item name="actionMenuTextColor">@color/ldrawer_color</item>
        <item name="android:textColorSecondary">@color/ldrawer_color</item>
    </style>

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

正如你所看到的,我已经宣布了

<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
Run Code Online (Sandbox Code Playgroud)

这是我的manifest.xml

 <application
        android:allowBackup="true"
        tools:replace="android:icon"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" …
Run Code Online (Sandbox Code Playgroud)

java xml android appcompatactivity

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

开发类似于"Google now"的应用程序 - 是否可以在没有键输入的情况下使用语音识别?

我正在尝试开发一个使用TTS引擎和语音识别的酷应用程序.到目前为止它还可以,但我想要更多.我想创建一个服务(我认为服务是正确的方式),总是"倾听",当有人说"ok google"或其他什么时,语音识别开始,就像谷歌现在.例如,如果你说"ok google"谷歌现在开始.我不知道从哪里开始所以我在这里直接询问是否有可能.我试着看这个帖子[这里](在任何时候都在听关键字,比如4.4上的"Ok google"),最后一个回答谈​​到了服务,正如我想的那样.有人能用我的代码帮助我吗?

例如,这是通过点击按钮开始语音识别的代码:

/**
 * Instruct the app to listen for user speech input
 */
private void listenToSpeech() {
    //start the speech recognition intent passing required data
    Intent listenIntent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    //indicate package
    listenIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, getClass().getPackage().getName());
    //message to display while listening
    listenIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Say a word!");
    //set speech model
    listenIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
    //specify number of results to retrieve
    listenIntent.putExtra(RecognizerIntent.EXTRA_MAX_RESULTS, 10);
    //start listening
    startActivityForResult(listenIntent, VR_REQUEST);
}
Run Code Online (Sandbox Code Playgroud)

你认为listenIntent只用语音而不按任何按钮就可以开始吗?这就是我的意思.

java android speech-recognition text-to-speech google-now

15
推荐指数
1
解决办法
8588
查看次数

无法将android.support.v7.widget.CardView导入Eclipse

我使用Eclipse,我正在尝试使用support-library-v7:21.+Lollipop中的new创建一个应用程序.

  • 创建了我的新项目
  • 在日食中导入 support-library-v7
  • 改变project-properties了支持库的行:target=android-2121个目标
  • 在21日改变了我的申请目标
  • 在我的项目中导入了库
  • 干净所有

毕竟我还是得到了无效的R声明.我重新启动了Eclipse,然后在重新导入库之后,似乎已经开始了!我创造了一个Tolbar和一个NavigationDrawer没有问题 - 它的工作原理.

现在,我想CardView在我的ListView项目中加入:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
   >
    <!-- A CardView that contains a TextView -->
    <android.support.v7.widget.CardView
        xmlns:card_view="http://schemas.android.com/apk/res-auto"
        android:id="@+id/card_view"
        android:layout_gravity="center"
        android:layout_width="200dp"
        android:layout_height="200dp"
        card_view:cardCornerRadius="4dp">
    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/codename"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/versione"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/link"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />
    <TextView
        android:id="@+id/timestamp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

    </android.support.v7.widget.CardView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

好吧,第一个错误:No …

java eclipse android android-support-library material-design

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

Android 4.1与ArrayMap崩溃

我使用这个logcat在我的代码中出错:

java.lang.NoClassDefFoundError: android.util.ArrayMap
at it.dd.multiplayerit.MainActivity.<init>(MainActivity.java:88)
at it.dd.multiplayerit.SwipeMainFragment$SectionsPagerAdapter.getItem(SwipeMainFragment.java:200)
at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:97)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832)
at android.support.v4.view.ViewPager.populate(ViewPager.java:982)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:15284)
at com.jeremyfeinstein.slidingmenu.lib.CustomViewAbove.onMeasure(CustomViewAbove.java:456)
at android.view.View.measure(View.java:15284)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:665)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:447)
at android.view.View.measure(View.java:15284)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:15284)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:861)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:602)
at android.view.View.measure(View.java:15284)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4816)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2367)
at android.view.View.measure(View.java:15284)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1867)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1111)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1292)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1009)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4236)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
at android.view.Choreographer.doCallbacks(Choreographer.java:555)
at android.view.Choreographer.doFrame(Choreographer.java:525)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4872)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511) …
Run Code Online (Sandbox Code Playgroud)

java android array-map autocompletetextview

7
推荐指数
1
解决办法
4010
查看次数

更改导航抽屉中所选项目的背景颜色

我想更改导航抽屉中所选项目的蓝色.我可以在点击某个项目但不在活动项目中时更改它.这是我使用的:在drawable文件夹中

<selector xmlns:android="http://schemas.android.com/apk/res/android">  
    <item android:state_activated="true" android:drawable="@color/default_color" />
    <item android:state_selected="true" android:drawable="@color/uva_color" />
    <item android:state_pressed="true" android:drawable="@color/uva_color" />
    <item android:state_focused="true" android:drawable="@color/default_color" />
    <item android:drawable="@color/default_color" />  
</selector>
Run Code Online (Sandbox Code Playgroud)

color.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="uva_color">#f2f8ee</color>
    <color name="default_color">#f2f8ee</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

然后在导航抽屉的布局:

<ListView
        android:id="@+id/left_drawer"
        android:layout_width="260dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:fitsSystemWindows="true"
        android:clipToPadding="false"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:listSelector="@drawable/activated_background"
        android:background="#ffff"/>
Run Code Online (Sandbox Code Playgroud)

那么,当前选择的项目不会改变颜色.任何想法?

使用java nav抽屉编辑:

public class MainActivity extends Activity {

private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
private ActionBarDrawerToggle mDrawerToggle;

private CharSequence mDrawerTitle;
private CharSequence mTitle;
CustomDrawerAdapter adapter;

List<DrawerItem> dataList;

@Override
protected void onCreate(Bundle savedInstanceState) { …
Run Code Online (Sandbox Code Playgroud)

java android android-layout navigation-drawer

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

当我回来时,Android片段在viewpager中为空

我有一个导航抽屉,其中有一个扩展片段的ViewPager.当我点击抽屉的项目时,我打开其中有三个片段的viewpager.它完美地运作.但如果我再次点击相同的抽屉项目再次打开viewpager,则viewpager为空..我可以看到标签但不是那里的片段.这是Viewpager:

public class ViewPagerManager extends Fragment {
    public static ViewPagerManager instance = null;
    Toolbar toolbar;
    public static PagerSlidingTabStrip tabs;
    public MyPagerAdapter adapter;
    public ViewPager pager;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_tabbed, container, false);
        instance = this;
        adapter = new MyPagerAdapter(getFragmentManager());

        pager = (ViewPager)view.findViewById(R.id.pager);
        tabs = (PagerSlidingTabStrip)view.findViewById(R.id.tabs);

        pager.setAdapter(adapter);
        tabs.setViewPager(pager);

        pager.setOffscreenPageLimit(3);

        adapter.notifyDataSetChanged();
        pager.invalidate();
        return view;
    }

    public class MyPagerAdapter extends FragmentPagerAdapter {

        private final String[] TITLES = { "One", "Two", "Three" };

        public MyPagerAdapter(FragmentManager …
Run Code Online (Sandbox Code Playgroud)

android android-adapter android-fragments android-viewpager

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

android.widget.RelativeLayout无法强制转换为android.support.v7.widget.RecyclerView

我的NavigationDrawer布局有问题,但有错误:

android.widget.RelativeLayout cannot be cast to android.support.v7.widget.RecyclerView
Run Code Online (Sandbox Code Playgroud)

这是我的onCreateView:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mRecyclerView = (RecyclerView) inflater.inflate(R.layout.fragment_drawer, container, false);
        mRecyclerView.setClipToPadding(false);
        mAdapter = new NavigationDrawerAdapter(getActivity(), new NavigationDrawerAdapter.ClickListener() {
            @Override
            public void onClick(int index) {
                selectItem(index);
            }

            @Override
            public boolean onLongClick(final int index) {
                Pins.Item item = mAdapter.getItem(index);
                Utils.showConfirmDialog(getActivity(), R.string.remove_shortcut,
                        R.string.confirm_remove_shortcut, item.getDisplay(getActivity()), new CustomDialog.SimpleClickListener() {
                            @Override
                            public void onPositive(int which, View view) {
                                Pins.remove(getActivity(), index);
                                mAdapter.reload(getActivity());
                            }
                        }
                );
                return false;
            }
        });
        mRecyclerView.setAdapter(mAdapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        mAdapter.setCheckedPos(mCurrentSelectedPosition); …
Run Code Online (Sandbox Code Playgroud)

android android-layout navigation-drawer android-recyclerview

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

FAB上的Alpha背景点击了

我正在使用库https://github.com/futuresimple/android-floating-action-button来创建非常好用的fab按钮.我尝试了几个库,但没有使用大多数应用程序中使用的效果与fab(或谷歌应用程序,如保持,收件箱),当点击工厂时,整个应用程序的背景为半透明的白色或黑色,这取决于.我找不到任何办法.是否有可能有一个例子或类似的东西来做这种效果?你可以在这张图片中看到我的意思: 在此输入图像描述

半黑背景

<?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" >

    <RelativeLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <include
            android:id="@+id/toolbar"
            layout="@layout/toolbar" />
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/semi_white_bg"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/white_semi_transparent"
        android:visibility="gone" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/listFrame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/content_frame"
        android:visibility="gone" >

        <TextView
            android:id="@+id/status"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/cabinet_color"
            android:fontFamily="sans-serif"
            android:gravity="center_vertical"
            android:paddingBottom="8dp"
            android:paddingLeft="16dp"
            android:paddingRight="16dp"
            android:paddingTop="8dp"
            android:textColor="#fff"
            android:textSize="17sp"
            android:visibility="gone" />

        <android.support.v7.widget.RecyclerView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/status"
            android:clipToPadding="false"
            android:scrollbars="vertical" />

        <LinearLayout
            android:id="@android:id/empty"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:orientation="vertical" >

            <ImageView
                android:id="@+id/emptyImage"
                android:layout_width="96dp"
                android:layout_height="96dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginBottom="16dp"
                android:scaleType="fitXY"
                android:src="?empty_image" />

            <TextView
                android:id="@+id/emptyText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

java android android-background floating-action-button

6
推荐指数
2
解决办法
5727
查看次数