小编Inv*_*Zim的帖子

根据口味在Android Studio中显示布局

我在Android Studio中有一个项目,该项目针对不同的颜色使用不同的风格(也有其他一些东西,但没关系)。

我想看看某个UI元素(全部由xml文件定义)如何具有非默认样式?

假设我必须调味,风味A是默认的,风味B不是。假设风味A主色为红色,风味B主色为绿色。

当我打开布局时,无论在构建变体中选择哪种样式,它们都将始终显示为红色。

我敢肯定有办法做到这一点,但我不知道怎么做。

Edit1:似乎我没有解释它(认为它是隐式的)。我的口味资源文件已经在不同的文件夹中。资源文件中的颜色具有相同的名称。那不是问题,问题是我看不到Android Studio内部布局中的颜色。

颜色位于单独的文件夹中,并且可以正常工作。当我构建和安装调味剂时,它们会使用它们的颜色。但是当我打开布局时,它总是在Android Studio中以默认颜色显示

android android-layout android-build-flavors

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

这个带有 IO 端口 0x61 和 0x20 的 x86 汇编语言代码有什么作用?

这是代码:

push ax
in al, 0x61
or al, 0x80  ; 10000000b
out 0x61, al
and al, 0x7F ; 01111111b
out 0x61, al
mov al, 0x20
out 0x20, al
pop ax
Run Code Online (Sandbox Code Playgroud)

它有什么作用?我只知道它连接到定时器中断。0x61发生了什么0x20

x86 assembly interrupt

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

微调器仅更新用户操作

我有IconText,里面有图像和文本视图,包括class和xml.

然后,我使用扩展的BaseAdapter(IconTextAdapter)作为适配器,使用这些IconTexts填充MainActivity内部的Spinner.

现在,IconText工作正常(显示它应该).但旋转器没有.

  1. 当我启动应用程序时,它会显示第一个IconText.
  2. 当我打开选择对话框时,一切都显示出来.
  3. 当我选择另一个项目时,选择对话框会折叠,旋转器不会显示IconText(即只有"向下箭头"才能打开选择对话框).

我仍然可以打开选择对话框并选择另一个.我注意到,如果我退出应用程序(返回按钮,而不是真的退出应用程序)并再次输入,则会显示正确的IconText.

我猜错误在于适配器?我会尝试避免发布大量代码[:

IconText.xml

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

    <ImageView android:id="@+id/it_image"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:src="@drawable/home"/>

    <TextView
        android:id="@+id/it_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="20sp"
        android:text="ABC"
        android:textColor="@color/black_overlay"
        android:textSize="20sp"
        android:textStyle="bold" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

IconText.java

public class IconText {

    static LayoutInflater inflator;

    public ImageView icon;
    public TextView text;
    public View view;

    public IconText(String title, int icon_id){
        Log.d("IconText", "Create");
        view = inflator.inflate(R.layout.icon_text, null);

        text = (TextView) view.findViewById(R.id.it_text);
        icon = (ImageView) view.findViewById(R.id.it_image);

        text.setText(title);
        icon.setImageResource(icon_id);
    }

    public static void initInflator(Context context){
        if(inflator != null) …
Run Code Online (Sandbox Code Playgroud)

java user-interface android spinner android-adapter

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

Android 主题中的窗口背景不起作用 - 启动画面

我正在尝试将启动画面添加到我的 Android 应用程序中。

我一直遵循这里的指示。这是我得到的标准方式,而且看起来很合乎逻辑。

所以这真的很简单吧?创建可绘制资源,在主题中使用它作为 windowBackground,使用主题?嗯,这对我不起作用...

显现:

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

    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/app_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme.Splashscreen">
        <activity android:name="euroicc.sicc.ui.MainActivity"
            android:theme="@style/AppTheme.Splashscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

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

款式:

<resources>

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:spinnerDropDownItemStyle">@style/mySpinnerItemStyle</item>
        <item name="android:itemBackground">@color/main_background</item>
        <item name="android:textColor">@color/text_default</item>


       <!--<item name="android:popupMenuStyle">@style/MyAlertDialog</item>-->
    </style>

    <style name="AppTheme.Splashscreen" parent="AppTheme">
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowTranslucentNavigation">true</item>

        <item name="android:windowBackground">@drawable/splashscreen_drawable</item>
    </style>

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

启动画面_可绘制:

<?xml …
Run Code Online (Sandbox Code Playgroud)

user-interface android splash-screen

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

这个宏有什么作用?

我正在做一个项目并使用过去几年的项目来帮助我了解如何做某些事情的想法.请注意,我没有盲目地复制,但书中没有很多东西.无论如何这是我不明白的宏:

#define PREPAREENTRY(numIVT,oldINT) \
    void interrupt int##numIVT(...){\
            IVTEntry::entries[##numIVT]->signalAll();\
            if (oldINT) IVTEntry::entries[##numIVT]->callOld();}\
    IVTEntry entry##numIVT(##numIVT,int##numIVT); 
#endif
Run Code Online (Sandbox Code Playgroud)

我不完全确定,但我认为我掌握了大部分内容.因此,PREPAREENTRY获取两个值,numIVT(IV表中的数字)和OldNT(旧中断).

然后它产生一个名为numIVT的中断函数,我可以将其设置为某个中断的中断函数,或者当该中断出现时会发生什么.

新的中断函数根据numIVT从一个对象数组中调用某个对象的signalAll().然后它检查它是否应该调用旧的中断函数并调用它.

这是新中断函数的结束.

但#endif之前的界限是什么?我一直在寻找整个项目,但找不到答案.在头脑风暴期间看这个项目之前,我想到了类似的东西,但没有最后一行.

如果有人能告诉我这些部件我是对还是错,我想我会挂掉,如果有人能告诉我这条神秘的线路是什么,我将不胜感激.

c++ macros interrupt

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

在发送带有回显的udp消息时设置源端口?

我正在使用

echo "This is my data" > /dev/udp/192.168.0.92/7891
Run Code Online (Sandbox Code Playgroud)

在bash脚本中以测试与设备的udp通信。然后,设备返回该消息。我通过wireshark看到我的源端口一直在变化。

无论如何,我想设置源端口,可以吗?

bash port udp netcat

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

圆形图标未显示在棉花糖上

我的测试设备是Android 6.0。它为所有应用程序使用圆形图标(我的除外)。由于这是唯一的测试设备并且我的手机不使用圆形图标,因此我必须使其在测试设备上运行。

我试图让它显示一个圆形图标,到目前为止我没有成功。

我已将所有 ic_launcher_round 图片设置为不同的分辨率。我还为“ic_launcher_round.xml”文件创建了一个“app_icon_round”图片。所有的 ic_launcher_round 图片都是合适的尺寸等等......我已经检查过多次了。

ic_launcher_round.xml:

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background" />
    <foreground android:drawable="@drawable/app_icon_round" />
</adaptive-icon>
Run Code Online (Sandbox Code Playgroud)

AndroidManifest.xml,:

<application
    ...
    android:icon="@mipmap/ic_launcher"
    android:roundIcon="@mipmap/ic_launcher_round"
    ...
</application>
Run Code Online (Sandbox Code Playgroud)

我总是使用 Android Studio 安装它。我注意到当我在启动屏幕上工作时,我需要手动卸载应用程序,重新启动手机,然后通过 Android Studio 安装它以注意更改。

我想我错过了一些小事,但不知道它是什么。我在互联网上看到的答案没有提到我没有做的事情。

icons android android-manifest android-icons

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

我不应该在没有警告的情况下获得作业?

我正在写一个字符串拆分函数.

所以,这个功能正在发挥作用.至少对我做的测试.

但在编译期间,我得到了

user/user_main.c:53:7:警告:赋值从整数中生成没有强制转换的指针[默认启用] splt = str_split(&length,pokusaj,'');

我不明白是什么问题.后来在我的代码中,我正常使用splt/length并获得所需的结果.那么,为什么我会收到这个警告?如果我强制转换它,警告会消失(显然),但是我不想抛出它,函数返回它返回的内容,所以我不需要强制转换结果.

码:

uint8_t** str_split(uint32_t* length, uint8_t* toSplit, uint8_t delimiter){
    uint8_t* curr = toSplit;
    uint8_t** poses = (uint8_t**) os_malloc(sizeof(uint8_t*)*STRTOK_MAX_LEN);
    uint32_t pos = 0;
    uint32_t len;
    uint8_t** dst;

    os_printf("String:--%s--\n", toSplit);

    while(pos < STRTOK_MAX_LEN) poses[pos++] = NULL;

    pos = 0;
    poses[pos++] = curr;
    curr++;
    while((curr = os_strchr(curr, delimiter) ) != NULL && pos < STRTOK_MAX_LEN){
        poses[pos++] = curr;
        curr++;
    }

    if(pos == 0) return 0;
    dst = (uint8_t**) os_malloc(sizeof(uint8_t*) * (pos));

    pos = 0;
    while(pos < …
Run Code Online (Sandbox Code Playgroud)

c pointers casting compiler-warnings

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

dos.h是什么类型的库(静态或动态)?

我正在为我的大学做一个项目.其中一点是我们不允许使用非静态库.当我处理中断时,我想使用dos.h来避免使用程序集(setvect()而不是一堆汇编代码行复杂化).

考虑使用库的部分的粗略翻译是:"...允许仅使用独立于平台(硬件和操作系统)的标准(静态)C/C++库.不允许使用特定的库系统主机或动态库(DLL)"

有人可以告诉我dos.h是什么类型的库?

c c++ static dynamic libraries

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

充气按钮的宽度和高度错误

我正在构建一个导航片段。有一个按钮始终存在(主按钮),其他按钮则动态添加和删除。

我有一个 xml 资源文件,我从中填充一个按钮,更改它的图标并将其添加到片段根布局中。

除了按钮大小之外,几乎所有功能都有效。之后的按钮大小为 0 (getWidth()/getHeight())。

按钮导航.xml

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/navigation_button"
    android:layout_width="60dp"
    android:layout_height="60dp"
    android:background="@drawable/icon_test"
    android:backgroundTint="@drawable/selector_bar_button"></Button>
Run Code Online (Sandbox Code Playgroud)

膨胀代码

Button butt = (Button) inflater.inflate(R.layout.button_navigation, null, false);

buttons.add(butt);
root_view.addView(butt);
Run Code Online (Sandbox Code Playgroud)

创建充气机

public void setParent(MainActivity activity){
        parent = activity;
        inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
Run Code Online (Sandbox Code Playgroud)

变量

MainActivity parent;
LayoutInflater inflater;

int index;

ArrayList<Button> buttons;
Button button_main;
LinearLayout root_view;
Run Code Online (Sandbox Code Playgroud)

主按钮,具有与button_navigation.xml 完全相同的代码,并出现在片段的布局文件中。主按钮的大小很好。

size android button layout-inflater

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

ic_launcher.xml 未被用作应用程序图标

我正在开发一个 Android 应用程序。

我正在尝试使用 ic_launcher.xml 和 ic_launcher_round.xml 作为应用程序图标,因为我认为这是正确的方法?

无论如何,我有一张 png 图像,108x108px,32 位颜色。我在 ic_launcher 和 ic_launcher_round 中都使用它作为:

<?xml version="1.0" encoding="utf-8"?>
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
    <background android:drawable="@drawable/ic_launcher_background" />
    <foreground android:drawable="@drawable/app_icon" />
</adaptive-icon>
Run Code Online (Sandbox Code Playgroud)

两个 xml 文件的代码相同。

问题是在较新的 os 版本(8.0+,圆形图标)上它运行良好,但在早期版本中它不起作用(7.0,方形图标)它根本不起作用,并且默认为标准的 android 图标。

我目前正在创建我将用来替换 mipmap 中的 ic_launcher.png 的所有图像,但除此之外我还能做些什么吗?

在清单中,我将它们用作:

android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher_round"
Run Code Online (Sandbox Code Playgroud)

xml android appicon

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