本文整理汇总了Java中android.support.v7.app.AppCompatActivity.findViewById方法的典型用法代码示例。如果您正苦于以下问题:Java AppCompatActivity.findViewById方法的具体用法?Java AppCompatActivity.findViewById怎么用?Java AppCompatActivity.findViewById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.app.AppCompatActivity
的用法示例。
在下文中一共展示了AppCompatActivity.findViewById方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setToolbarAsBack
import android.support.v7.app.AppCompatActivity; //导入方法依赖的package包/类
public static void setToolbarAsBack(final AppCompatActivity activity, int id, String title) {
Toolbar toolbar = (Toolbar) activity.findViewById(id);
toolbar.setTitle(title);
activity.setSupportActionBar(toolbar);
if (activity.getSupportActionBar() != null) {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.finish();
}
});
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);
}
}
示例2: initToolbar
import android.support.v7.app.AppCompatActivity; //导入方法依赖的package包/类
public static Toolbar initToolbar(@NonNull final AppCompatActivity activity, @IdRes int toolbarId, boolean canBack, @Nullable CharSequence title) {
Toolbar toolbar = (Toolbar) activity.findViewById(toolbarId);
if (toolbar == null) {
throw new IllegalStateException(
"The subclass of ToolbarActivity must contain a toolbar.");
}
activity.setSupportActionBar(toolbar);
ActionBar actionBar = activity.getSupportActionBar();
if (actionBar != null) {
if (canBack) {
actionBar.setDisplayHomeAsUpEnabled(true);
if (title != null) {
actionBar.setTitle(title);
} else {
actionBar.setDisplayShowTitleEnabled(false);
}
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activity.onBackPressed();
}
});
}
}
return toolbar;
}
示例3: showAdMobBanner
import android.support.v7.app.AppCompatActivity; //导入方法依赖的package包/类
/**
* Show the AdMob banner.
* https://firebase.google.com/docs/admob/android/quick-start
* @param activity activity
*/
public static void showAdMobBanner(final AppCompatActivity activity) {
// Load an ad into the AdMob banner view.
AdView adView = (AdView) activity.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
}
示例4: getToolbar
import android.support.v7.app.AppCompatActivity; //导入方法依赖的package包/类
public static Toolbar getToolbar(AppCompatActivity activity) {
return (Toolbar) activity.findViewById(R.id.toolbar);
}
示例5: onActivityCreated
import android.support.v7.app.AppCompatActivity; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
mList = new ArrayList<>();
mCoordinatorLayout = (CoordinatorLayout) activity.findViewById(R.id.coordinator_layout);
mSortType = mPrefs.getInt(Constants.KEY_FAVORITES_SORT, 0);
mIsGrid = mDisplayType == 0;
mGridColumnCount = mPrefs.getInt(Constants.KEY_GRID_COLUMN_COUNT, getResources().getInteger(R.integer.grid_num_cols));
mListColumnCount = mPrefs.getInt(Constants.KEY_LIST_COLUMN_COUNT, getResources().getInteger(R.integer.list_num_cols));
mLayoutManager = new GridLayoutManager(getActivity(), mIsGrid ? mGridColumnCount : mListColumnCount);
mRecyclerView.setLayoutManager(mLayoutManager);
// Create an empty adapter we will use to display the loaded data.
mAdapter = new AnimeRecyclerAdapter(mList, mDisplayType, getActivity(), true, mAnimeClickListener);
mAdapter.setRecyclerView(mRecyclerView);
mRecyclerView.setAdapter(mAdapter);
}
//Restore previous state
if (savedInstanceState != null) {
//Selection
mAdapter.onRestoreInstanceState(savedInstanceState);
if (mAdapter.getSelectedItemCount() > 0) {
mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new RecordOptions((AppCompatActivity) getActivity()));
}
//Previously serialized activated item position
if (savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
setSelection(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
}
示例6: onActivityCreated
import android.support.v7.app.AppCompatActivity; //导入方法依赖的package包/类
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// We have a menu item to show in action bar.
setHasOptionsMenu(true);
AppCompatActivity activity = (AppCompatActivity) getActivity();
if (activity != null) {
mCoordinatorLayout = (CoordinatorLayout) activity.findViewById(R.id.coordinator_layout);
mAppBarLayout = (ControllableAppBarLayout) activity.findViewById(R.id.appbar_layout);
if (mPrefs == null)
mPrefs = PreferenceManager.getDefaultSharedPreferences(activity);
mDisplayType = Integer.parseInt(mPrefs.getString(Constants.KEY_LIBRARY_DISPLAY_TYPE, "0"));
mAnimeMap = new HashMap<String, Anime>();
mPrevPath = new Stack<String>();
if (TextUtils.isEmpty(mPath)) {
if (StorageUtils.getDataDirectory() != null)
mPath = StorageUtils.getDataDirectory().getAbsolutePath();
else
mPath = Environment.getExternalStorageDirectory().getAbsolutePath();
}
// Create an empty adapter we will use to display the loaded data.
mAdapter = new LibraryRecyclerAdapter(getActivity(), mDisplayType, mLibraryClickListener);
mRecyclerView.setAdapter(mAdapter);
}
//Restore previous state
if (savedInstanceState != null) {
ArrayList<String> mPrevPathList = savedInstanceState.getStringArrayList(Constants.ANIME_PREV_PATH_LIST);
if (mPrevPathList != null && !mPrevPathList.isEmpty() && mPrevPath.size() != mPrevPathList.size()) {
for (String s : mPrevPathList) {
mPrevPath.push(s);
}
}
if (mAdapter != null) {
//Selection
mAdapter.onRestoreInstanceState(savedInstanceState);
if (mAdapter.getSelectedItemCount() > 0) {
mActionMode = ((AppCompatActivity) getActivity()).startSupportActionMode(new RecordOptions((AppCompatActivity) getActivity()));
}
//Previously serialized activated item position
if (savedInstanceState.containsKey(STATE_ACTIVATED_POSITION))
setSelection(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
}
}
// Prepare the loader. Either re-connect with an existing one,
// or start a new one.
getLoaderManager().initLoader(0, null, this);
}