小编Mik*_*ike的帖子

用于在Android中启动活动的自定义动画无法按预期工作

我对Android有点新意.我需要在活动打开时在我的应用中自定义动画.

我在我的应用程序中使用了以下代码 styles.xml

<style name="YourAnimation.Activity" parent="@android:style/Animation.Activity">
    <item name="android:windowEnterAnimation">@anim/fade_in</item>
    <item name="android:windowExitAnimation">@anim/fade_out</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后将样式应用于同一文件中的主题.

<style name="YourTheme" parent="android:Theme.Translucent">
    <item name="android:windowAnimationStyle">@style/CustomAnimationActivity</item>
</style>
Run Code Online (Sandbox Code Playgroud)

然后在我的主题中添加主题 AndroidManifest.xml

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/YourTheme" >
</application>
Run Code Online (Sandbox Code Playgroud)

但是,当我运行它时,会发生以下错误.

错误

我想我需要在我的项目中的某处添加动画ml文件.但是,不知道该怎么做.有人请帮帮我.

提前致谢.:)

-编辑-

这里是 fade_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <alpha
        android:duration="1000"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0"/>
</set>
Run Code Online (Sandbox Code Playgroud)

这里是 fade_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="0.0"/>
</set>
Run Code Online (Sandbox Code Playgroud)

崩溃日志

05-20 15:36:47.216    3557-3557/com.myayubo E/AndroidRuntime? FATAL EXCEPTION: main
    Process: com.myayubo, PID: 3557
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myayubo/com.myayubo.PreSplash}: java.lang.IllegalStateException: You need …
Run Code Online (Sandbox Code Playgroud)

animation android

16
推荐指数
1
解决办法
919
查看次数

Webview无法接受cookie

我正在创建一个基于WebView的Android应用程序,使用户可以登录移动运营商.当我运行应用程序时,WebView会打开网站,但我收到一条消息,表明WebView不允许使用cookie.我尝试过各种我在这里找到的代码,但都没有.谁能帮我?这是我正在使用的代码:

//in oncreate
final CookieSyncManager cookieSyncManager = CookieSyncManager.createInstance(this);
final CookieManager cookieManager = CookieManager.getInstance();
cookieManager.setAcceptCookie(true);
cookieManager.removeSessionCookie();
String[] cookies = getCookie("https://myaccount.ee.co.uk/login-dispatch/?fa=register");
for (String cookie : cookies) {
    cookieManager.setCookie("https://myaccount.ee.co.uk/login-dispatch/?fa=register", cookie);
}
cookieSyncManager.sync();
webView.loadUrl("https://myaccount.ee.co.uk/login-dispatch/?fa=register");
Run Code Online (Sandbox Code Playgroud)

和getCookies方法:

public String[] getCookie(String siteName) {
     CookieManager cookieManager = CookieManager.getInstance();
     String cookies = cookieManager.getCookie(siteName);
     String[] cookiesArray = cookies.split(";");
     return cookiesArray;
}
Run Code Online (Sandbox Code Playgroud)

cookies android android-webview android-websettings android-cookiemanager

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

Android ScrollView设置显示内容的高度

我在尝试解决布局中具有静态高度可滚动区域的问题时遇到了很多麻烦.我有三个长列表需要在同一个屏幕上显示,顺序显示所有条目是完全不切实际的,因为如果你想跳过一个类别,你需要滚动过去可能有数百个条目.

假设我有一个内部带有线性布局的滚动视图,我希望这个占据屏幕上最大250dp的高度,并且一旦填充了多于250dp空间的条目,就可以独立滚动.

我现在拥有的是:

<ScrollView
    android:minWidth="25px"
    android:minHeight="150px"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:id="@+id/XXXXXXX"
    android:scrollbars="vertical">

    <LinearLayout
        android:orientation="vertical"
        android:minWidth="25px"
        android:minHeight="25px"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/XXXXXX" />
</ScrollView>
Run Code Online (Sandbox Code Playgroud)

当填充时,只要滚动视图和线性布局需要适合内容并显示所有内容并且显示所有内容而不是具有250dp/px的"窗口"(任何测量将是好的)并且内容可在其中滚动,则只需拉伸.

我是android平台的新手,所以也许答案是显而易见的,我只是不懂语言,但任何帮助都将不胜感激!谢谢

---求助:将一个linearLayout放在ScrollView外面的高度.

xml layout android scrollview xamarin

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

如何从Webview(swift)打开Safari View Controller

我有一个当前使用webview的应用程序,当在webview中单击某些链接时,它会在Safari中打开这些链接.我现在想要实现Safari视图控制器(SVC),而不是将其启动到Safari应用程序.我做过研究,看过SVC的例子; 但是,我所看到的只是通过点击按钮打开SVC.有没有人有任何建议让我看看或尝试?

这是我的一些代码:

func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
    if navigationType == UIWebViewNavigationType.LinkClicked {
        let host = request.URL!.host!;
        if (host != "www.example.com"){
            return true
        } else {
            UIApplication.sharedApplication().openURL(request.URL!)
            return false
        }
    return true

}

func showLinksClicked() {

    let safariVC = SFSafariViewController(URL: NSURL(string: "www.example.com")!)
    self.presentViewController(safariVC, animated: true, completion: nil)
    safariVC.delegate = self    }

func safariViewControllerDidFinish(controller: SFSafariViewController) {
    controller.dismissViewControllerAnimated(true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud)

uiwebview ios swift sfsafariviewcontroller

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

片段事务加载空视图但片段在旋转设备后显示

我正在构建一个由谷歌文档设计的导航抽屉,但我有一个问题,片段没有被替换.http://developer.android.com/training/implementing-navigation/nav-drawer.html

应用程序首次加载时,将加载默认片段.单击抽屉列表上的另一个项目会留下空视图但是在旋转设备时,会加载所选的片段.

public void selectNavActivty(int position){
    // TODO Changing between the different screens selection
    fragment = null;
    switch (position) {
        case 0:
            fragment = OverLay.newInstance();
            break;
        case 1: 
            fragment = Dummy.newInstance();
            break;
        }

    if(fragment != null) {
        // attach added to handle viewpager fragments
        FragmentTransaction trans = getSupportFragmentManager().beginTransaction();
        trans.replace(R.id.content_frame, fragment).attach(fragment)
            .addToBackStack(null);

        trans.commit();
        getFragmentManager().executePendingTransactions();
    } else {
        Log.d("Drawer Activity","Error in creating Fragment");
    }
}
Run Code Online (Sandbox Code Playgroud)

android fragmenttransaction navigation-drawer

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

如何在Android中将值从一个片段传递到另一个片段?

我是Fragments的新手.我想将String值从一个Fragment传递给另一个Fragment.这该怎么做?我用以下方式调用了我的碎片.请一步一步指导我.

String cid = id.getText().toString();
Fragment fr = new FriendFragment();
android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, fr);
ft.commit(); 
Run Code Online (Sandbox Code Playgroud)

android bundle android-fragments

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

Android文本到不同语言的语音

我想创建一个可以支持不同语言的应用程序.

"默认"语言没有问题:

tts.setLanguage(Locale.ENGLISH);
Run Code Online (Sandbox Code Playgroud)

还有其他一些:

Locale l = new Locale("ru","RU");
tts.setLanguage(l);
Run Code Online (Sandbox Code Playgroud)

但是很多其他人都不行,例如:

Locale l = new Locale("hu","HU");
tts.setLanguage(l);
Run Code Online (Sandbox Code Playgroud)

我也试过"hu","hu-HU","hu-rHU","HU"......但是没有......

此外,它不适用于土耳其语,希腊语,荷兰语,捷克语......

java android locale

8
推荐指数
1
解决办法
2540
查看次数

App Links支持多个子域名

我一直在阅读支持Android应用程序链接的文档和我的应用程序支持的子网站工作的网站,但有太多的子域,它们是动态构建的.我想知道是否有一种方法可以支持许多子域而无需在intent-filter标记中指定所有子域.

以下是来自google的示例的链接:http://developer.android.com/training/app-links/index.html#request-verify 该示例位于支持应用程序链接多个子域位置.

我认为正则表达式可以工作,但显然在定义主机时不支持.我不想列出所有这些,因为这意味着必须在创建每个新子域的情况下推送新版本

<activity ...>
    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="https" />
        <data android:host=".*.example.org" />
        <data android:pathPattern="/.*" />
    </intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)

我宁愿不使用第三方库或服务..但任何适合您的建议将不胜感激,了解如何使这项工作.

subdomain android deep-linking intentfilter applinks

7
推荐指数
2
解决办法
3582
查看次数

强制布局刷新/重绘android?

我想改变布局的位置,75ms后将其返回到第一个位置进行移动,这是我的代码:

for(int i = 0; i < l1.getChildCount(); i++) {  
    linear = (LinearLayout) findViewById(l1.getChildAt(i).getId());  
    LayoutParams params = new LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT);  
    params.bottomMargin = 10;  
    linear.setLayoutParams(params);  
    SystemClock.sleep(75);
}   
Run Code Online (Sandbox Code Playgroud)

问题是应用程序停止750毫秒,并没有做任何事情.我试过 invalidate(),refreshDrawableState(),requestLayout(), postInvalidate(),并尝试调用onResume(),onRestart(),onPause().

layout android refresh

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

BigTextStyle通知未从FirebaseMessagingService扩展

我写了下面的方法来显示我的Android 5.1设备上的FCM通知.当我在FirebaseMessagingService中运行代码时,它只是提供单行通知,如果我在Activity中运行相同的代码,则会发出可扩展通知.

我基本上需要我的长FCM文本通知来扩展通知而不是显示部分通知文本.

任何线索?

private void showNotif(String messageBody){

     Intent intent = new Intent(this, MainActivity.class);
     intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);

     // Constructs the Builder object.
     NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(getApplicationContext())
         .setSmallIcon(R.drawable.ic_launcher)
         .setContentTitle(getString(R.string.app_name))
         .setContentText(messageBody)
         .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
         .setAutoCancel(true)
         .setContentIntent(pendingIntent)
         /*
          * Sets the big view "big text" style and supplies the
          * text (the user's reminder message) that will be displayed
          * in the detail area of the expanded notification.
          * These calls are ignored by the …
Run Code Online (Sandbox Code Playgroud)

android android-notifications firebase firebase-notifications

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