小编muk*_*esh的帖子

当用户选择语言时如何更改应用程序的语言?

我希望我的应用程序支持三种语言西班牙语,葡萄牙语和英语.并选择在app中选择语言.我已经做了

1)3个可绘制的文件夹drawable-es,drawable-pt,drawable.

2)3个值文件夹值-es,values-pt,values.根据语言更改String.xml值.

我有imageView来选择语言.当点击它打开菜单包括选项英语,西班牙语,葡萄牙语.

我通过此代码在选项选择中在应用程序内设置Locale

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.en:
             Locale locale = new Locale("en"); 
             Locale.setDefault(locale);
             Configuration config = new Configuration();
             config.locale = locale;
             getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
             Toast.makeText(this, "Locale in English !", Toast.LENGTH_LONG).show();
             break;

        case R.id.pt:
             Locale locale2 = new Locale("pt"); 
             Locale.setDefault(locale2);
             Configuration config2 = new Configuration();
             config2.locale = locale2;
             getBaseContext().getResources().updateConfiguration(config2, getBaseContext().getResources().getDisplayMetrics());

             Toast.makeText(this, "Locale in Portugal !", Toast.LENGTH_LONG).show();
             break;

        case R.id.es:
             Locale locale3 = new Locale("es"); 
             Locale.setDefault(locale3);
             Configuration config3 = new Configuration();
             config3.locale = locale3;
             getBaseContext().getResources().updateConfiguration(config3, …
Run Code Online (Sandbox Code Playgroud)

android localization

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

如何使用蓝牙热敏打印机打印发票收据

我必须使用热敏打印机打印发票收据.我用Zjiang Thermal打印机打印收据.他们还提供手动和演示项目.在演示项目中,他们使用libray"btsdk.jar"来实现连接和打印.

我已成功建立打印机和Android设备之间的连接.但是没有文本对齐(中心,左,右)和单元格宽度,高度的准则.

试过了.它只通过更改格式2变量来更改文本高度.

我如何通过蓝牙打印机打印发票.

还请解释这一节 -

 byte[] cmd = new byte[3];
 cmd[0] = 0x1b;
 cmd[1] = 0x21;
 cmd[2] |= 0x10;
Run Code Online (Sandbox Code Playgroud)

cmd 2 - 用于更改字体高度使用cmd [0]和cmd 1

代码将打印消息发送到蓝牙打印机在演示项目中

 String msg = "";
 byte[] cmd = new byte[3];
 cmd[0] = 0x1b;
 cmd[1] = 0x21;
 cmd[2] |= 0x10;
 mService.write(cmd);           
 mService.sendMessage("Congratulations!\n", "GBK"); 
 cmd[2] &= 0xEF;
 mService.write(cmd);          
 msg = "  You have sucessfully created communications between your device and our bluetooth printer.\n\n"
      +" …
Run Code Online (Sandbox Code Playgroud)

android thermal-printer android-bluetooth

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

"无法覆盖SherlockActivity的最终方法"

我试图用Actionbarsherlock扩展我的活动,当我这样做时,我收到了一个错误

"无法覆盖SherlockActivity的最终方法"

我的活动有这些进口

    import java.io.IOException;
    import com.actionbarsherlock.app.SherlockActivity;
    import android.os.Bundle;
    import android.accounts.Account;
    import android.accounts.AccountManager;
    import android.accounts.AccountManagerCallback;
    import android.accounts.AccountManagerFuture;
    import android.accounts.AuthenticatorException;
    import android.accounts.OperationCanceledException;
    import android.app.Activity;
    import android.content.Intent;
    import android.util.Log;
    import android.view.Menu;
    import android.view.View;
    import android.widget.Button;
Run Code Online (Sandbox Code Playgroud)

请指导我如何解决它?

android

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

如何在android中更改下拉视图的标题?

我的布局中有一个微调器,并使用android:prompt="@string/year".

默认提示如下所示:

默认提示看起来像

现在我的问题是:

  1. 如何将默认图标更改为其他图像?
  2. 如何让“年份”文本以红色显示在中心?
  3. 如何将背景颜色更改为黄色(存在“年份”文本和图标的背景)?

我的自定义适配器类

private class MyCustomSpinnerAdapter extends ArrayAdapter<ArrayList> {
        private ArrayList<String> objectsList = new ArrayList<String>();

        @SuppressWarnings("unchecked")
        public MyCustomSpinnerAdapter(Context context, int textViewResourceId,
                ArrayList objects) {
            super(context, textViewResourceId, objects);
            this.objectsList = objects;
        }

        @Override
        public View getDropDownView(int position, View convertView,
                ViewGroup parent) {
            return getCustomView(position, convertView, parent);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            return getCustomView1(position, convertView, parent);
        }

        public View getCustomView(int position, View convertView,
                ViewGroup parent) {
            LayoutInflater inflater = getLayoutInflater(); …
Run Code Online (Sandbox Code Playgroud)

android android-widget android-layout

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

WebSocket - 状态码403和状态消息 - 禁止

我正在使用下面提到的Apprtc.Follow视频通话应用程序.

  1. https://github.com/njovy/AppRTCDemo
  2. https://github.com/Piasy/AppRTC-Android

当我将url更改为我的自定义服务器而不是apprtc服务器时,1分钟后视频通话将被断开.我失去了与服务器的连接.

为避免服务器丢失连接,我们需要在约30秒内定期ping服务器.

但是上面提到的AppRTC项目正在使用jar文件(autobanh.jar)来连接websocket,但是在库中,sendPing mentod是私有的,因此无法访问.

问题1 -有没有办法ping websocket服务器.

替换websocet库之后尝试用下面提到的库更改了websocket库

  1. https://github.com/Koredotcom/android-kore-sdk/tree/master/BotsSDK/korebotsdklib/src/main/java/kore/botssdk/autobahn
  2. https://github.com/martindale/soundtrack.io-android/tree/master/src/de/tavendo/autobahn

在重新放置websocket库之后,现在我可以访问sendPing方法了.但是在视频通话过程中60秒后我的连接丢失了.

平方法 -

 public void sendPingMessageToServer() {
    try {
        WebSocketMessage.Ping ping = new WebSocketMessage.Ping();
//            ping.mPayload="ping to server".getBytes();
        mWebSocketWriter.sendPing(ping);

    } catch (Exception e) {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

在取消注释ping.mPayload行时,我得到BufferOverflowException.

定时器30秒

  private void startConnectionCheckTimer() {
    timerInstance.scheduleAtFixedRate(new TimerTask() {
        @Override
        public void run() {
            try {
               ws.sendPingMessageToServer();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }, 0, 30 * 1000);
}
Run Code Online (Sandbox Code Playgroud)

请建议60秒后如何避免断电.

android websocket apprtc

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

导航组件 - ViewPager 片段中的 findNavController 不起作用

我有一个带有 3 个菜单选项(主页、服务等)的底部导航。主页选项卡片段包含 TabLayout 和 ViewPager。

ViewPager 有 2 个片段 - CurrentDetailFargment 和 PreviousDetailFragment。

ViewPager 有效,之后当我使用 findNavController() 应用单击 CurrentDetailFargment 按钮时,我得到异常。

参考

导航付款屏幕

findNavController().
navigate(R.id.action_currentBillFragment_to_paymentOptionsFragment)
Run Code Online (Sandbox Code Playgroud)

例外

java.lang.IllegalArgumentException: navigation destination XXXXXXX:id/action_currentBillFragment_to_paymentOptionsFragment is unknown to this NavController
    at androidx.navigation.NavController.navigate(NavController.java:789)
    at androidx.navigation.NavController.navigate(NavController.java:730)
    at androidx.navigation.NavController.navigate(NavController.java:716)
    at androidx.navigation.NavController.navigate(NavController.java:704)
    at com.bses_yamuna.user.home.currentbill.view.CurrentBillFragment.navigateToPayNow
Run Code Online (Sandbox Code Playgroud)

根据例外情况- 我没有在我的图表中提到 'action_currentBillFragment_to_paymentOptionsFragment' id。但我已经声明了它的图形。此图与 BottomNaviagtion 一起使用。

请让我知道我解决了这个问题。

活动布局部分-

    <fragment
        android:id="@+id/navigationHost"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:defaultNavHost="true"
        app:layout_constraintBottom_toTopOf="@+id/bottomNavigation"
        app:layout_constraintTop_toBottomOf="@+id/constraint_top"
        app:navGraph="@navigation/menu_navigation" />

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/bottomNavigation"
        style="@style/Widget.BottomNavigationView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:itemIconTint="@drawable/bottom_navigation_item_colors"
        app:itemTextColor="@drawable/bottom_navigation_item_colors"
        app:labelVisibilityMode="labeled"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:menu="@menu/bottom_nav_menu_modify" />
Run Code Online (Sandbox Code Playgroud)

适配器

 class ViewPagerAdapter …
Run Code Online (Sandbox Code Playgroud)

navigation android

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

在Android中 - 如何在没有打开Tweet对话框(消息对话框)的情况下直接向Twitter中的身份验证用户的以下用户发送推文

我想将推文发布给以下用户身份验证用户.使用Twitter-4j库进行身份验证.我已获得以下用户的列表(姓名和ID)但无法在没有打开对话框的情况下发布推文.我正在使用此链接进行身份验证

问题 - 如何直接发布推文给Android中的身份验证用户的以下用户wihout打开Tweet对话框(消息对话框)

1.在twitterButton上单击一个使用webview打开的新活动

    twitterButton=(Button) findViewById(R.id.twitter);
    twitterButton.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub


        mTwitter = new TwitterFactory().getInstance();
        mRequestToken = null;
        mTwitter.setOAuthConsumer(TwitterConstants.CONSUMER_KEY,
                TwitterConstants.CONSUMER_SECRET);
        String callbackURL = getResources().getString(
                R.string.twitter_callback);
        try {
            mRequestToken = mTwitter.getOAuthRequestToken(callbackURL);
            System.out.println("URL"
                    + mRequestToken.getAuthenticationURL());
        } catch (TwitterException e) {
            e.printStackTrace();
        }
        Intent i = new Intent(MMSExampleActivity.this,
                TwitterScreen.class);
        i.putExtra("URL", mRequestToken.getAuthenticationURL());
        System.out.println("Url ==== "
                + mRequestToken.getAuthenticationURL());
        startActivityForResult(i, TWITTER_AUTH);

    }
       });
Run Code Online (Sandbox Code Playgroud)

2.在onActivityResult(int requestCode,int resultCode,Intent data)方法中

                 if (resultCode == Activity.RESULT_OK) {
                String …
Run Code Online (Sandbox Code Playgroud)

twitter android

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

如何从sqlite数据库android计算一行表的行

我想在android中计算一个表的行.我使用了2种方法但没有成功并获得警告消息

Launch timeout has expired, giving up wake lock!
 Activity idle timeout for HistoryRecord{44e26a30 com.india.screen/.CategoryList}
Run Code Online (Sandbox Code Playgroud)

我试过了-

String query="Select count(*) from Holyplace_Tbl";
Run Code Online (Sandbox Code Playgroud)
  1. 使用rawQuery

    public void countRows(String query){

    Cursor mcursor = assetDatabaseHelper.executeQuery(query);
    mcursor.moveToFirst();
    int icount = mcursor.getInt(0);
    System.out.println("NUMBER IN DB: " + icount);
    mcursor.close();
    
    Run Code Online (Sandbox Code Playgroud)

    }

  2. 使用DatabaseUtils

    public int countRows(String query)
    {
    
       int sometotal = (int) DatabaseUtils.longForQuery(sqliteDatabaseObj, query, null);
      return sometotal;
     }
    
    Run Code Online (Sandbox Code Playgroud)

    AssetDatabaseOpenHelper.class

sqlite android

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

垂直方向的 Recyclerview 在屏幕水平滚动时上下滚动

我需要创建一个包含全屏视频的列表。我使用 PagerSnapHelper 作为全屏子项目。我有一个 Exoplayer 实例并在滚动时更改视频。视频也会在水平滚动时发生变化。

RecyclerView.OnScrollListener() 方法也在水平滚动时调用。

请建议我如何解决这些问题。

  1. RecyclerView 只能垂直滚动。
  2. RecyclerView.OnScrollListener() 不应在水平滚动时调用

1. 滚动监听器

class SnapOnScrollListener(
private val snapHelper: SnapHelper,
var behavior: Behavior = Behavior.NOTIFY_ON_SCROLL,
var onSnapPositionChangeListener: OnSnapPositionChangeListener? = null
) : RecyclerView.OnScrollListener() {

enum class Behavior {
    NOTIFY_ON_SCROLL,
    NOTIFY_ON_SCROLL_STATE_IDLE
}


override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
    System.out.println("dx.. $dx  dy $dy")
    if (behavior == Behavior.NOTIFY_ON_SCROLL) {
        maybeNotifySnapPositionChange(recyclerView)
        System.out.println("dx.. $dx  dy $dy snapChange")
    }
}

override fun onScrollStateChanged(recyclerView: RecyclerView, newState: Int) {
    System.out.println("dx......")

    if ( behavior == Behavior.NOTIFY_ON_SCROLL_STATE_IDLE …
Run Code Online (Sandbox Code Playgroud)

android kotlin android-recyclerview pagersnaphelper

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