我想在UI中使用2种语言,并在我的资源文件中为它们分别使用字符串值res\values\strings.xml:
<string name="tab_Books_en">Books</string>
<string name="tab_Quotes_en">Quotes</string>
<string name="tab_Questions_en">Questions</string>
<string name="tab_Notes_en">Notes</string>
<string name="tab_Bookmarks_en">Bookmarks</string>
<string name="tab_Books_ru">?????</string>
<string name="tab_Quotes_ru">??????</string>
<string name="tab_Questions_ru">???????</string>
<string name="tab_Notes_ru">???????</string>
<string name="tab_Bookmarks_ru">????????</string>
Run Code Online (Sandbox Code Playgroud)
现在我需要在我的应用中动态检索这些值:
spec.setContent(R.id.tabPage1);
String pack = getPackageName();
String id = "tab_Books_" + Central.lang;
int i = Central.Res.getIdentifier(id, "string", pack);
String str = Central.Res.getString(i);
Run Code Online (Sandbox Code Playgroud)
我的问题是i = 0.
为什么它在我的情况下不起作用?
我需要使用自定义命令扩展android Webview的文本选择菜单。到目前为止,我已经设法通过以下方式实现我的自定义Webview文本选择菜单:
public class CustomActionWebView extends WebView {
static String TAG = "CustomActionWebView";
ActionMode mActionMode;
int mMenuID;
Activity mParentAct;
ActionSelectListener mActionSelectListener;
ButtonClickListener mButtonClick;
public CustomActionWebView(Context context) {
super(context);
}
public CustomActionWebView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomActionWebView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void setActionMenu(int mActionMenu, Activity ParentAct) {
setWebViewClient(new CustomWebViewClient());
this.mMenuID = mActionMenu;
mParentAct = ParentAct;
}
private ActionMode resolveActionMode(ActionMode actionMode) {
if (actionMode != null) {
final Menu menu = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用带有导航图和导航控制器的导航组件来实现简单的导航。我的 MainActivity 带有带有汉堡图标和应用程序标题的操作栏、抽屉导航和内容区域。
内容区域是我显示不同片段的地方。
内容区域首先加载我的 homescreenFragment,其中包含 4 个按钮(新闻、事件、时间表、个人资料) - 每个按钮都将片段加载到我的 MainActivity 的内容区域中。它工作正常,唯一的问题如下:当我按下新闻按钮并从主屏幕导航到NewsFragment时,它会加载片段 OK 并将操作栏标题更改为 News。汉堡包图标更改为“向上按钮”图标,但是当我按下它时,应用程序会打开导航抽屉,就像我按下汉堡包图标一样,而不是将我导航回主屏幕。
如何使“向上”按钮向上而不显示左侧导航抽屉?
这是我的 MainActivity.java:
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.NavigationUI;
public class MainActivity extends AppCompatActivity {
Toolbar m_toolbar;
DrawerLayout m_drawer;
ActionBarDrawerToggle m_toggle;
NavigationView m_navigationView;
NavController m_navController;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_toolbar = findViewById(R.id.toolbar);
setSupportActionBar(m_toolbar);
m_drawer = findViewById(R.id.drawer_layout);
m_navigationView = findViewById(R.id.nav_drawer_view); …Run Code Online (Sandbox Code Playgroud) 我试图覆盖 onOverScrolled() 但它没有被触发:
public class MyRecyclerView extends RecyclerView {
public MyRecyclerView(@NonNull Context context) {
super(context);
}
public MyRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyRecyclerView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
protected void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);
Toast.makeText(getContext(), "overScrolled", Toast.LENGTH_SHORT).show();
}
}
Run Code Online (Sandbox Code Playgroud)
我的 RecyclerView 有 recyclerView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
我有TabActivity ,底部有标签,由几个不同的活动组成,如下所示:
public class HomeScreen extends TabActivity {
private TabHost mTabHost;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
try{
setContentView(R.layout.hometabs);
Resources res = getResources(); // Resource object to get Drawables
mTabHost = getTabHost(); // The activity TabHost
TabHost.TabSpec spec; // Reusable TabSpec for each tab
Intent intent; // Reusable Intent for each tab
String strName;
// Create an Intent to launch an Activity for the tab (to be reused)
strName=Central.Res.getString(R.string.tab_Books);
intent = new Intent().setClass(this, BookList.class);
spec = mTabHost.newTabSpec(strName).setIndicator("",
res.getDrawable(R.drawable.ic_menu_database)) …Run Code Online (Sandbox Code Playgroud) android ×4
android-architecture-navigation ×1
overscroll ×1
resources ×1
string ×1
tabactivity ×1
title ×1
webview ×1