小编use*_*901的帖子

Android棒棒糖改变导航栏颜色

在我的应用程序中,我需要更改底部导航栏颜色.我看了许多帖子,但无法找到解决方案.我正在使用appCompat库.需要帮助.提前致谢.

在此输入图像描述

V21/styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light">
       <item name="android:windowBackground">@drawable/bgpreview</item>
       <item name="android:colorPrimary">@color/MyColor</item>
       <item name="android:colorPrimaryDark">@color/MyColor</item>
       <item name="android:windowContentOverlay">@null</item>
       <item name="android:textColorPrimary">@color/MyColor</item>
       <item name="colorAccent">@color/MyColor</item>
       <!-- darker variant for the status bar and contextual app bars -->
       <item name="android:windowContentTransitions">true</item>
       <item name="android:windowAllowEnterTransitionOverlap">true</item>
       <item name="android:windowAllowReturnTransitionOverlap">true</item>
       <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
       <item name="android:windowSharedElementExitTransition">@android:transition/move</item>

       <item name="windowActionBar">false</item>
       <item name="android:textAllCaps">false</item>

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

android colors navigationbar android-5.0-lollipop

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

Android Api 23更改导航视图headerLayout textview

我在android中测试Navigation Drawer示例项目,我在导航视图配置文件头中设置文本时遇到问题.

这是我的代码:

MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });

    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();

    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);

    TextView text = (TextView) findViewById(R.id.textView);
    texto.setText("HELLO");
}
Run Code Online (Sandbox Code Playgroud)

activity_main.xml中

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" …
Run Code Online (Sandbox Code Playgroud)

android header nullpointerexception textview navigation-drawer

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

Android以编程方式更改导航抽屉菜单项文本

我的应用程序中有新的导航抽屉,我想从代码中动态更改导航视图菜单项标题文本.我看了很多帖子,但我想不通,我怎么能这样做.我怎样才能正确实现这一目标?

MainActivity.java

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

setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                .setAction("Action", null).show();
    }
});

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
        this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();

NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

}
Run Code Online (Sandbox Code Playgroud)

activity_main_drawer.xml

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

<group android:checkableBehavior="single">
    <item android:id="@+id/nav_camara" android:icon="@android:drawable/ic_menu_camera"
        android:title="Import" />
    <item android:id="@+id/nav_gallery" …
Run Code Online (Sandbox Code Playgroud)

android text menu menuitem navigation-drawer

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

Android推出Twitter意图

我使用下面的代码通过意图启动Twitter,但它不起作用.我的手机上安装了Twitter应用程序.

Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Content to share");
PackageManager pm = contexto.getPackageManager();
List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0);
for (final ResolveInfo app : activityList) {
    if ("com.twitter.android.PostActivity".equals(app.activityInfo.name)) {
        final ActivityInfo activity = app.activityInfo;
        final ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
        shareIntent.addCategory(Intent.CATEGORY_LAUNCHER);
        shareIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        shareIntent.setComponent(name);
        contexto.startActivity(shareIntent);
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

我尝试调用活动时获取异常:

android.content.ActivityNotFoundException:无法找到显式活动类{com.twitter.android/com.twitter.android.PostActivity}; 你有没有在AndroidManifest.xml中声明这个活动?

twitter android android-intent

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

android棒棒糖scrollview边缘效果颜色

在我的应用程序中,我更改过度滚动发光效果颜色,如下所示:

int glowDrawableId = contexto.getResources().getIdentifier("overscroll_glow", "drawable", "android");
Drawable androidGlow = contexto.getResources().getDrawable(glowDrawableId);
assert androidGlow != null;
androidGlow.setColorFilter(getResources().getColor(R.color.MyColor), PorterDuff.Mode.SRC_ATOP);
Run Code Online (Sandbox Code Playgroud)

但当我更新到棒棒糖这个代码崩溃.我收到以下错误代码:

FATAL EXCEPTION: main
Process: com.myproject.myapp, PID: 954
android.content.res.Resources$NotFoundException: Resource ID #0x0
at android.content.res.Resources.getValue(Resources.java:1233)
at android.content.res.Resources.getDrawable(Resources.java:756)
at android.content.res.Resources.getDrawable(Resources.java:724)
Run Code Online (Sandbox Code Playgroud)

似乎棒棒糖中缺少overscroll_glow资源.我怎样才能在棒棒糖中实现这一目标?

提前致谢.

android scrollview android-5.0-lollipop

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

Android更改导航视图菜单背景

在我的应用程序中,我想更改导航视图菜单背景,但我不知道如何做到这一点.我观看的所有帖子都解释了如何更改每个菜单项背景,但我只需要更改菜单的整个背景.

这就是我要改变的,整个白色背景:

在此输入图像描述

activity_main_drawer.xml:

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

<group android:checkableBehavior="single">
    <item android:id="@+id/nav_camara" android:icon="@android:drawable/ic_menu_camera"
        android:title="Import" />
    <item android:id="@+id/nav_gallery" android:icon="@android:drawable/ic_menu_gallery"
        android:title="Gallery" />
    <item android:id="@+id/nav_slideshow" android:icon="@android:drawable/ic_menu_slideshow"
        android:title="Slideshow" />
    <item android:id="@+id/nav_manage" android:icon="@android:drawable/ic_menu_manage"
        android:title="Tools" />
</group>

<item android:title="Communicate">
    <menu>
        <item android:id="@+id/nav_share" android:icon="@android:drawable/ic_menu_share"
            android:title="Share" />
        <item android:id="@+id/nav_send" android:icon="@android:drawable/ic_menu_send"
            android:title="Send" />
    </menu>
</item>

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

反正有没有从activity_main_drawer布局更改白色背景?

activity_main.xml中:

 <?xml version="1.0" encoding="utf-8"?>
 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout"
android:layout_width="match_parent" android:layout_height="match_parent"
android:fitsSystemWindows="true" tools:openDrawer="start">

<include layout="@layout/app_bar_main" android:layout_width="match_parent"
    android:layout_height="match_parent" />

<android.support.design.widget.NavigationView android:id="@+id/nav_view"
    android:layout_width="wrap_content" android:layout_height="match_parent"
    android:layout_gravity="start" android:fitsSystemWindows="true"
    app:headerLayout="@layout/nav_header_main" app:menu="@menu/activity_main_drawer" />

 </android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

提前致谢.

navigation android background menu view

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

Android Navigation View以编程方式设置菜单

在我的应用程序中,我想根据某些条件传递某些菜单.

这是布局:

 <android.support.design.widget.NavigationView
        android:id="@+id/nav_view_free"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:background="@color/Color_White"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer_1"
        />
Run Code Online (Sandbox Code Playgroud)

我想要做的就是根据某些条件动态更改@ menu/activity_main_drawer_1.

我该如何以编程方式执行此操作?

navigation android menu view

12
推荐指数
3
解决办法
9009
查看次数

OSX和iOS之间的iCloud Core数据共享

我有一个OSX和iOS的应用程序,都使用iCloud在它们之间共享核心数据.当我在iPhone上进行更改时,我可以在OSX应用程序中看到它们,并NSPersistentStoreDidImportUbiquitousContentChangesNotification在两个应用程序中调用它们,因此iOS - > Mac运行良好.但是当我在Mac应用程序中进行一些更改时,我无法在iPhone中看到它们.iPhone永远不会打电话给NSPersistentStoreDidImportUbiquitousContentChangesNotification.我能改变Mac的唯一方法是在iPhone上做一些改变.然后我可以看到所有的变化.

两个项目中的iCloud集成是一样的.核心数据数据模型是相同的.权利也是一样的.

我的所有代码都基于这个库:http://ossh.com.au/design-and-technology/software-development/sample-library-style-ios-core-data-app-with-icloud-integration/

为什么iPhone在iPhone上进行一些更改之前没有改变Mac?有任何想法吗?

另一个问题

在我的应用程序中,当用户启用iCloud时,我检查是否已经是iCloud上的文件.如果文件存在,则用户可以选择从iCloud文件还原核心数据或从本地存储启动新副本.要开始新副本,我使用以下代码:

- (void)startNewCopy
{
    [self removeICloudStore];
    [self moveStoreToIcloud];
}

- (void)removeICloudStore
{
    BOOL result;
    NSError *error;
    // Now delete the iCloud content and file
    result = [NSPersistentStoreCoordinator removeUbiquitousContentAndPersistentStoreAtURL:[self icloudStoreURL]
                                                                             options:[self icloudStoreOptions]
                                                                             error:&error];
    if (!result)
    {
        NSLog(@"Error removing store");
    }
    else
    {
        NSLog(@"Core Data store removed.");
        // Now delete the local file
        [self deleteLocalCopyOfiCloudStore];
    }

}


- (void)deleteLocalCopyOfiCloudStore {
   // We need to get the URL …
Run Code Online (Sandbox Code Playgroud)

macos core-data ios icloud

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

鼠标悬停时,Cocoa osx NSButton显示文字

在我的Mac应用程序中,当用户将鼠标指针移到按钮上时,我想显示一些信息文本.像这样的东西:

在此输入图像描述

我怎样才能正确实现这一目标?

提前致谢.

macos cocoa text mouseover nsbutton

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

Android从webview创建包含多个页面的pdf文档

我使用Android的PdfDocument框架(链接)从我的webview内容创建一个pdf文档.pdf创建得很好,但它只是一页文档.当webview内容很大时,我需要创建一个多页文档.我只需要在页面中分割WEBVIEW内容.我怎样才能实现这一目标?我不想使用iText或任何第三方库.

需要帮助.提前致谢.

// create a new document
PdfDocument document = new PdfDocument();

// create a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(width, height, 1).create();

// start a page
PdfDocument.Page page = document.startPage(pageInfo);

// draw something on the page
View content = myWebview;
content.draw(page.getCanvas());

// finish the page
document.finishPage(page);

FileOutputStream fos;
try {
    fos = new FileOutputStream(fileNameWithPath, false);
    // write the document content
    document.writeTo(fos);

} catch (FileNotFoundException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

// close …
Run Code Online (Sandbox Code Playgroud)

pdf android document webview multipage

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