小编ans*_*992的帖子

如何更改Android菜单项的自定义字体?

我有以下Android Java和XML代码.我想更改我的应用程序的菜单项的字体.我只知道我们可以使用setTypeface更改TextView的字体,但无论如何都无法找到菜单项.

JAVA代码 - :

@Override
public boolean onCreateOptionsMenu(Menu menu) {    
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    return true;
}

@Override    
public boolean onOptionsItemSelected(MenuItem item) {
   switch (item.getItemId()) {     
        case R.id.action_refresh1:                                          
            Toast.makeText(this, "Item1 Selected", Toast.LENGTH_SHORT)
            .show();      
        break;

        case R.id.action_refresh2:                                          
            Toast.makeText(this, "Item2 Selected", Toast.LENGTH_SHORT)
            .show();      
            break;

        default:      
            break;
   }
}
Run Code Online (Sandbox Code Playgroud)

XML代码 - :

<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
    android:id="@+id/action_refresh1"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="Item1"/>

<item
    android:id="@+id/action_refresh2"
    android:orderInCategory="100"
    android:showAsAction="always"
    android:title="Item2"/>
</menu>
Run Code Online (Sandbox Code Playgroud)

我想更改两个菜单项的字体,但不知道如何为菜单项集成settypface.

android menuitem

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

Android BLE特性getValue返回null

我正在尝试将文本数据写入我的BLE设备.所以,我正在关注Android蓝牙GATT课程来完成这项任务.但我发现将文本写入特征是好的,但在尝试检索特征值时,它返回null.

MyCode:

public void writeCharacteristic(BluetoothGattCharacteristic characteristic,
                                String text) {

    String TAGS ="MyBeacon";

    if (mBluetoothAdapter == null || mBluetoothGatt == null) {
        Log.w(TAGS, "BluetoothAdapter not initialized");
        return;
    } else {
        Log.w(TAGS, "Writting ... ");
    }
    byte[] data = hexStringToByteArray(text);


    Log.w(TAGS, "Writting text = " + data);


    try {
        characteristic.setValue(URLEncoder.encode(text, "utf-8"));
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    boolean writeValue = mBluetoothGatt.writeCharacteristic(characteristic);

    Log.w(TAGS, "Writting Status = " + writeValue);

}
Run Code Online (Sandbox Code Playgroud)

//成功onCharacteristicWrite也被调用//

   @Override
    public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
        super.onCharacteristicWrite(gatt, …
Run Code Online (Sandbox Code Playgroud)

android bluetooth-lowenergy beacon

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

如何使用node.js在mongodb中插入文档数组?

我想使用 node.js 向 mongodb 插入文档数组,但在插入时只插入第一个数据。

[{
  "userid": "5664",
  "name": "Zero 2679",
  "number": "1234562679",
  "status": "contact",
  "currentUserid": "Abcd"
 }, 
 {
  "userid": "5665",
  "name": "Zero 3649",
  "number": "1234563649",
  "status": "contact",
  "currentUserid": "Xyz"
}]
Run Code Online (Sandbox Code Playgroud)

示例代码

collection.insert([{"userid": userid,"name": name,"number": number,"status": status,"currentUserid": currentUserid}], function(err, docs) {
    if (err) {
        res.json({error : "database error"});
    }else {
       collection.find({currentUserid:currentUserid}).toArray(function(err, users) {
          res.send(users);
       });
    }});
Run Code Online (Sandbox Code Playgroud)

但它仍然只插入第一个值,请告诉我如何插入所有这些文件。

请仔细阅读我的帖子并建议我一些解决方案。

arrays mongodb node.js

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

为什么搜索栏的左侧和右侧都有空间?

我正在研究,Seekbar并且发现了一个问题。左侧和右侧均存在默认空间。我需要搜索栏为全宽。我做了match_parentfill_parent但是那没用。

在此处输入图片说明

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

   <SeekBar
      android:id="@+id/seek_bar_controller"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:padding="0dp" />
 </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

您可以按照快照快照进行参考,左右两侧都有空格。

请仔细阅读我的帖子并提出一些解决方案。

xml android seekbar android-layout android-studio

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

如何将应用编译到 Android TV Box?

我对 Android TV 应用程序开发很陌生。所以,我在互联网上搜索 Android TV Box,我很困惑我可以在哪里连接 USB 电缆来编译我的代码,然后我可以在 TV Box 上安装一个新的应用程序。

我对 Android TV apis 非常清楚,我已经在 Android Studio 中完成了简要介绍。所以,只有我需要知道如何将应用安装到 Android 电视盒。

关联

请建议我一些解决方案。

android android-tv

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