小编Ser*_*o76的帖子

工具栏不适用于使用appcompat v7的pre-lollipops设备

我正在使用材料appcompatv7为工具栏和菜单抽屉做一个简单的代码.一切都在带有棒棒糖的Nexus 5上完美运行,但在前棒棒糖(4.1或4.4)设备崩溃时.问题在于定义风格.如果有人能告诉我故障在哪里,我会把我的代码.

这是我的主要活动:

import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.widget.Toolbar;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Hello extends ActionBarActivity {

    private ActionBarDrawerToggle toggle;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hello);

        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        toggle = new ActionBarDrawerToggle(
                this, 
                drawerLayout, 
                R.string.navigation_drawer_open, 
                R.string.navigation_drawer_close);
        toggle.setDrawerIndicatorEnabled(true);
        drawerLayout.setDrawerListener(toggle);

        ListView lv_navigation_drawer = (ListView) findViewById(R.id.lv_navigation_drawer);
        lv_navigation_drawer.setAdapter(new ArrayAdapter<String>(
                this, 
                android.R.layout.simple_list_item_1, 
                new String[] {"Screen 1", "Screen 2", "Screen 3"}));
    }

    @Override …
Run Code Online (Sandbox Code Playgroud)

android toolbar android-5.0-lollipop

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

AltBeacon的Android Beacon Library获得主要,次要和UUID

我要说的第一件事是这是我第一次使用信标.我正在使用AltBeacon

目前我有几件工作,例如,当我进入一个地区或离开它时...也正确地获得了与信标的距离.这非常有效.我也得到UUID,主要和未成年人..但不知道我是否正确地做到了.

这是我的代码:

public class Hello extends Activity implements BeaconConsumer {

    protected static final String TAG = "readme";
    private BeaconManager beaconManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.hola);


        beaconManager = BeaconManager.getInstanceForApplication(this);

        beaconManager.getBeaconParsers().add(new BeaconParser().
                setBeaconLayout("m:0-3=4c000215,i:4-19,i:20-21,i:22-23,p:24-24"));
        beaconManager.bind(this);

    }

    @Override
    public void onBeaconServiceConnect() {

        try {
            beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", Identifier.parse("MY_UUID"), Identifier.parse("1"), null));

        } catch (RemoteException e) {
        }

        beaconManager.setRangeNotifier(new RangeNotifier() {
            @Override
            public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) {
                if (beacons.size() > 0) {
                    Log.i(TAG, "The first beacon I see is …
Run Code Online (Sandbox Code Playgroud)

uuid android ibeacon-android altbeacon

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

带有灰色图标的白色导航栏

我怎样才能在我的 android 应用程序中获得这种风格?白色导航栏和灰色图标。一个例子是打开应用程序抽屉时。 在此处输入图片说明

我尝试了很多选择,但没有成功。应用程序 minSdkVersion 是 21,棒棒糖。

我已经看到了这个解决方案,但我还没有设法应用它:

状态栏变白,后面不显示内容

android themes navigationbar android-styles

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

在 okhttp 请求中使用证书与 android

我工作的应用程序的服务器使用证书来允许请求。例如,我已将其安装在桌面 Chrome 浏览器中,并且运行良好。它是扩展名为 .cer 的普通证书

现在我必须让这个证书也能在我的 android 应用程序中工作,老实说,我从来没有做过,我有点迷茫。

为了发出请求,我使用 okhttp2,正如您在此示例中看到的:

 public String makeServiceCall(String url, JSONObject data) {
        final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
        OkHttpClient client = new OkHttpClient();
        client.setConnectTimeout(45, TimeUnit.SECONDS);
        client.setReadTimeout(45, TimeUnit.SECONDS);
        client.setProtocols(Arrays.asList(Protocol.HTTP_1_1));

        RequestBody body = RequestBody.create(JSON, data.toString());
        Request request = new Request.Builder()
                .url(url)
                .header("Accept","application/json")
                .post(body)
                .build();
        try {
            Response response = client.newCall(request).execute();
            return response.body().string();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
Run Code Online (Sandbox Code Playgroud)

到目前为止,一切都完美无缺,但是在搜索和阅读教程、示例等(其中许多来自本页)之后,我还没有设法让它工作。使其与证书一起使用。

从未这样做过,并且已经有点困惑,我将不胜感激以下澄清:

  • 我拥有的 .cer 格式的证书,我想我应该将其转换为另一种格式以便能够在 android 中使用它......是否正确?如果正确,我该怎么做?

好的,我已经将我的证书转换为 BKS 并托管在 res/raw …

android certificate okhttp

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

在 android 中使用 DayNight 主题的状态栏的颜色

我正在将主题 Theme.AppCompat.DayNight.NoActionBar 应用于我的应用程序。在浅色主题中,我希望状态栏为白色,而在深色主题中,我希望状态栏为黑色。

我不能让状态栏变成白色,字母变成黑色,反之亦然。

这是我的风格:

 <style name="AppTheme.Base" parent="Theme.AppCompat.DayNight.NoActionBar">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="android:windowDrawsSystemBarBackgrounds">true</item>
        <item name="android:windowNoTitle">true</item>
        <item name="windowActionBar">false</item>
        <item name="colorControlNormal">@color/primary_dark</item>
        <item name="colorControlHighlight">@color/primary_dark</item>
        <item name="android:textColorPrimary">@color/letter_medium_emphasis</item>
        <item name="android:textColorSecondary">@color/letter_high_emphasis</item>
    </style>
Run Code Online (Sandbox Code Playgroud)

这是我的颜色文件:

<resources>
    <color name="primary">#ffffff</color>
    <color name="primary_dark">#0336ff</color>
    <color name="letter_high_emphasis">#de000000</color>
    <color name="letter_medium_emphasis">#99000000</color>
    <color name="letter_medium_disabled">#61000000</color>
</resources>
Run Code Online (Sandbox Code Playgroud)

我尝试添加参数 @color/primary 但我仍然得到同样的结果,状态栏是白色的,同样来自状态栏的文本也是白色的。

在浅色主题中显示带有深色字母的白色状态栏以及在深色主题中反之的方式是什么?

提前致谢。

android android-dark-theme theme-daynight

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

更改 Theme.MaterialComponents 的 TextInputLayout.OutlinedBox 的光标颜色

在我的应用程序中,我使用 textfield.TextInputLayout 和 textfield.TextInputEditText 作为输入文本,而不是通常的 EditText。这是我的观点:

 <com.google.android.material.textfield.TextInputLayout
        android:id="@+id/inputId"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginStart="@dimen/fab_margin"
        android:layout_marginEnd="@dimen/fab_margin"
        android:focusedByDefault="false"
        android:enabled="true"
        android:hint="@string/userHint"
        android:textColor="@color/letter_medium_emphasis"
        app:boxCornerRadiusBottomEnd="@dimen/OutLinedBoxCorners"
        app:boxCornerRadiusBottomStart="@dimen/OutLinedBoxCorners"
        app:boxCornerRadiusTopEnd="@dimen/OutLinedBoxCorners"
        app:boxCornerRadiusTopStart="@dimen/OutLinedBoxCorners"
        app:boxStrokeColor="@color/letter_medium_emphasis"
        app:counterEnabled="true"
        app:counterMaxLength="20"
        app:helperText="@string/rememberId"
        app:helperTextEnabled="true"
        app:hintTextColor="@color/letter_medium_emphasis"
        app:startIconDrawable="@drawable/ic_account_circle_black_24dp"
        app:startIconTint="@color/primary_dark">

        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxLines="1"
            android:inputType="text"
            android:fontFamily="@font/poppins_medium" />

    </com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

一切都是正确的,除了一件事,即光标和文本选择器的颜色。我附上一张图片来更好地解释自己。

在此输入图像描述

我一直在读,显然这已经发生在更多的人身上。光标在那里,但始终是白色的。

在此输入图像描述

我找到了解决方案,但它们都适用于 FilledBox.Dense 类型。我正在使用 OutlinedBox,但没有任何效果。我发现的最好的解决方案是这个

问题是,正如我所说,它适用于 FilledBox.Dense 类型,而不适用于 OutlinedBox。

有人可以告诉我如何适应这个解决方案或如何以其他方式改变颜色?

我尝试使用 OutlinedBox 类型对其进行调整,但没有成功。

提前致谢。

android colors android-textinputlayout material-components-android

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

在viewpagerindicator中使用自定义字体

在我的项目中,我使用的是字体android:fontFamily ="sans-serif-light",并且正常工作.

我也在使用库viewpagerindicator.我想在viewpagerindicator中使用字体android:fontFamily ="sans-serif-light",但是找不到怎么做

我已经尝试使用android:fontFamily = "sans-serif-light"<com.viewpagerindicator.TitlePageIndicator ...和的风格,但没有成功.

我也尝试过:

PageIndicator mIndicator = (TitlePageIndicator) findViewById (R.id.indicator);
Typeface myTypeface = Typeface.createFromAsset (getAssets (), "fonts / Roboto-Light.ttf");
mIndicator.setTypeface (myTypeface);
Run Code Online (Sandbox Code Playgroud)

但这不起作用..

我感谢任何帮助.

感谢致敬

android custom-font viewpagerindicator

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

ViewPagerIndicator可以工作,但不会移动

我在我的项目中使用了库"ViewPagerIndicator".

我在xml中有ViewPager和ViewPagerIndicator,好吧.

我的问题是我无法编写正确的适配器.我已将它与Jake Warton在其示例中使用的适配器进行了比较,但无法使其正常工作ViewPager正常工作,在屏幕上看到的ViewPagerIndicator ......但不会移动.

如果脉冲,例如,在viewpagerindicator的第二项上移动viewpager ...但从不移动viewpagerindicator

在此输入图像描述

这是主要的活动代码:

//...
        pager = (ViewPager) findViewById(R.id.pager);

        ViewPagerAdapter adapterViewPager = new ViewPagerAdapter(getSupportFragmentManager());
        adapterViewPager.addFragment(new FRG_home());
        adapterViewPager.addFragment(new Fragment_One());
        adapterViewPager.addFragment(new Fragment_Two());
        adapterViewPager.addFragment(new Fragment_Three());

        pager.setOffscreenPageLimit(5);
        pager.setAdapter(adapterViewPager);

        PageIndicator mIndicator = (TitlePageIndicator)findViewById(R.id.indicator);
        mIndicator.setViewPager(pager);

//...
Run Code Online (Sandbox Code Playgroud)

这是Jake Wharton示例中使用的适配器代码:

class TestFragmentAdapter extends FragmentPagerAdapter implements IconPagerAdapter {
    protected static final String[] CONTENT = new String[] { "This", "Is", "A", "Test", };
    protected static final int[] ICONS = new int[] {
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher,
            R.drawable.ic_launcher
    };

    private int mCount = CONTENT.length;

    public TestFragmentAdapter(FragmentManager fm) { …
Run Code Online (Sandbox Code Playgroud)

android viewpagerindicator

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

在Android中将文本转换为HTML

我正在寻找方法在android中的html中用空格和符号转换文本,

例如:

"Hi this is my text" to "Hi%20this%20is%20my%20text"
Run Code Online (Sandbox Code Playgroud)

还有符号......

任何人都知道这么简单吗?

我发现将html文本转换为纯文本.

提前致谢......

html android text

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

在Android中显示12或24小时格式的TimePicker

我的TimePickerDialog有问题.首先检测用户的设备是否有12或24小时格式的时间:

…
String format;
…
if (DateFormat.is24HourFormat(this)) {
Log.i("control","Format 24");
format=("24");
} else {
 Log.i("control","Format 12");
format=("12");
}
…
Run Code Online (Sandbox Code Playgroud)

现在我打算使用am或pm选项显示TimePicker,具体取决于格式:

…
if(format.equals("24"){
view.setIs24HourView(true);
} else {
view.setIs24HourView(true);
} …
Run Code Online (Sandbox Code Playgroud)

这是完整的代码TimePickerDialog:

public class AlarmPreferencesActivity extends ListActivity
…
TimePickerDialog timePickerDialog = new TimePickerDialogs(this, new TimePickerDialog.OnTimeSetListener(){

            @Override
            public void onTimeSet(TimePicker view, int hours, int minutes) {

                Calendar newAlarmTime = Calendar.getInstance();
                newAlarmTime.set(Calendar.HOUR_OF_DAY, hours);
                newAlarmTime.set(Calendar.MINUTE, minutes);
                newAlarmTime.set(Calendar.SECOND, 0);
                alarm.setAlarmTime(newAlarmTime);
                alarmPreferenceListAdapter
                .setMathAlarm(getMathAlarm());
                alarmPreferenceListAdapter
                .notifyDataSetChanged();

            }},
            alarm.getAlarmTime().get(Calendar.HOUR_OF_DAY),
            alarm.getAlarmTime().get(Calendar.MINUTE), true);


        timePickerDialog.setCancelable(true);
        timePickerDialog.setCustomTitle(getLayoutInflater().inflate(R.layout.custom_hours, null));
        timePickerDialog.show();
        }
Run Code Online (Sandbox Code Playgroud)

我的问题是我不知道在哪里包括view.setIs24HourView (true) …

android dialog time-format android-timepicker

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